2011-03-08 7 views
0

사용자가 선택한 세그먼트를 선택한 후에 IB를 통해 아무것도 선택하지 않는 UISegmentControl이 있습니다. 어떻게 그렇게 선택하지 않는가?선택 후 selectedSegmentIndex를 선택하지 않음

//Show question method 
-(void)question:(NSInteger)i 
{ 
    // Path to the plist 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Question" ofType:@"plist"]; 

    // Set the plist to an array 
    NSArray *array = [NSArray arrayWithContentsOfFile:path]; 

    //Check the number of entries in the array 
    NSInteger numCount = [array count]; 
    if(i <numCount) 
    { NSDictionary *dict = [array objectAtIndex:i];//load array index 0 dictionary data 
     self.title = [NSString stringWithFormat:@"Question %d", i+1];//set the nav bar title 
     quest.text = [dict valueForKey:@"Question"];//Set the Question to storage 
     ans.text = [dict valueForKey:@"Answer"];//Set the Answer to storage 
     NSInteger option = [[dict valueForKey:@"NumberOfOption"] integerValue ];//Check options to determine the question type 

     //check if the option is is a QRCode or Multiple Choices Question 
     if (option ==0) 
     { 
      QRbutton.alpha = 1; //show the QR Code Button If there is no options 
      OptionsAnswer.alpha = 0;//Hide Option if there is no options 
     } 
     else 
     { 
      QRbutton.alpha = 0.0;//Hide QR Code Button if there is options 
      OptionsAnswer.alpha = 1;//Show Option if there is options 
      [OptionsAnswer setTitle:[dict valueForKey:@"Option1"] forSegmentAtIndex:0];//Set Option Answer Value 
      [OptionsAnswer setTitle:[dict valueForKey:@"Option2"] forSegmentAtIndex:1];//Set Option Answer Value 
      [OptionsAnswer setTitle:[dict valueForKey:@"Option3"] forSegmentAtIndex:2];//Set Option Answer Value 
      [OptionsAnswer setTitle:[dict valueForKey:@"Option4"] forSegmentAtIndex:3];//Set Option Answer Value 
      [OptionsAnswer addTarget:self action:@selector(OptionAnswerCheck) forControlEvents:UIControlEventValueChanged];//Call action when options is being selected 
     } 

    } 
    else { 

     //if question is all answered, it will prompt an alert for end game video. 
     UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Well Done" 
                 message:@"You Have Answered All The Questions, Oh Wait A Minute I Heard A Cracking Sound...." delegate:self 
               cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; [alert show];; 
     [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO]; 

    } 

} 




//Check if the selected Option is correct 
-(IBAction)OptionAnswerCheck 
{ 
    //define a persistant location to save which question has been answered 
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];//question storages 

//pass the value from the selected option to a string 
    //NSString * selectedTitle = ([OptionsAnswer selectedSegmentIndex] >= 0) ? [OptionsAnswer titleForSegmentAtIndex:[OptionsAnswer selectedSegmentIndex]] : 
    NSString * selectedTitle = [OptionsAnswer titleForSegmentAtIndex:[OptionsAnswer selectedSegmentIndex]]; 


    NSLog(@"Selected Title = %@",selectedTitle);//test 

    //check if the selected value is equal to the answers 
    if ([selectedTitle compare:self.ans.text] ==NSOrderedSame) 
    { 
     //Popup to say answer Correct 
     UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Correct!" 
                 message:@"Nice Work, Lets Move On To The Next Question" delegate:nil 
               cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; [alert show];; 
     [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO]; 

     //increase the question number 
     [self question:++currentQuestion]; 
     //save increased question 
     [userDefaults setInteger:currentQuestion forKey:@"currentQuestion"]; 

    } 
    else 
    { 
     //Popup to say answer Wrong 
     UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Incorrect" 
                 message:@"Close! But That's Not Right, Try Another Answer" delegate:nil 
               cancelButtonTitle:@"Try Again." otherButtonTitles:nil] autorelease]; [alert show];; 
     [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO]; 
    } 
    //OptionsAnswer.selectedSegmentIndex = UISegmentedControlNoSegment; 

} 

답변

1

Xcode의 개발자 문서에서 setMomentary:을 검색하면됩니다.

+0

고마워요, 그 문제가 해결되었습니다 ....하지 않았다 jus 작은 진드기가 – Desmond

1

나는 당신이 여기 요구하는지 전혀 모르겠어요,하지만 난 당신이 YESmomentary 속성을 설정하려는 생각합니다.

재산은 IB의 검사관에도 있습니다. (스크린 샷을 게시 할 수 없으며 iPhone에 있습니다.)

+0

안녕하세요 고마워, 그 .... 문제가 해결되지 않았다 jus 작은 진드기가 – Desmond

관련 문제