2013-07-19 17 views
1

IBAction返回類型的選擇器'go'沒有正確響應。如果單擊按鈕時文本字段爲空,即其值爲零,則流程應返回'if'部分而不是'else'。但是,當我第二次點擊按鈕時它工作正常。可能是什麼問題?UIButton沒有響應,因爲它應該在iOS6中的單視圖應用程序中

下面是來自實現文件的代碼,即ViewController.m,我已經實現了go選擇器。

@synthesize textField = _textField; 


- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    //Clear the text field 
    self.textField.text =nil; 
} 

NSString *s; 

-(IBAction)go:(id)sender 
{ 
    [self.textField resignFirstResponder]; 

    if (self.textField.text == nil) 
    { 
     s = [NSString stringWithFormat:@" Enter Your Name First " ]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Blank Field : " 
                 message:s 
                 delegate:self 
               cancelButtonTitle:@"OKAY" 
               otherButtonTitles:nil]; 
     [alert show]; 
    } 
    else 
    { 
     s = [NSString stringWithFormat:@"Hello %@ " , self.textField.text]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello " 
                 message:s 
                 delegate:self 
               cancelButtonTitle:@"Thanks" 
               otherButtonTitles:nil]; 

     [alert show];  
    } 
} 

請幫忙。 在此先感謝。

+0

可能取代'nil'測試'「」'的? –

回答

0

而不是使用nil作爲你比較我會改用更具體的東西像

if ([self.textfield.text length] > 0) 
{ 

} 
else 
{ 

} 
+0

非常感謝先生。它按我期望的那樣工作。 –