2012-07-16 56 views
1

我希望當用戶在文本字段中輸入一個數字時,這個數字將用於很多操作,但是這個數字不能是0,我創建了一個錯誤消息,如果用戶點擊文本框上的「下一個」按鈕以顯示0,但是該消息沒有時間出現,因爲該按鈕將用戶帶到另一個視圖,我該如何告訴按鈕留在該視圖中直到數字是好的?我的按鈕實現:按鈕不能前進到另一個視圖如果

- (IBAction)calc:(id)sender { 

    int mynumber; 
    mynumber = [textfieldnumber.text intValue]; 

    if (mynumber==0) { 

     NSString *errorstr = [[NSString alloc] initWithFormat:@"Please, set the number of people..."]; 
     labelerror.text = errorstr; 


    } 


} 
+0

如何按鈕將用戶帶到另一個看法?你在使用故事板嗎?你有沒有連接到按鈕的繼續? – 2012-07-16 17:05:02

+0

我們需要更多的代碼 – achi 2012-07-16 17:05:08

+0

這個按鈕讓用戶使用模態。是的,故事板... – 2012-07-16 17:13:06

回答

1

從故事板中刪除Segue。然後創建一個從文件所有者或選定視圖底部的小黃框到新的modalViewController的新文件。設置它的標識符並記住它。然後改變這:

- (IBAction)calc:(id)sender { 

int mynumber; 
mynumber = [textfieldnumber.text intValue]; 

if (mynumber==0) { 

    NSString *errorstr = [[NSString alloc] initWithFormat:@"Please, set the number of people..."]; 
    labelerror.text = errorstr; 


} 


} 

這樣:

- (IBAction)calc:(id)sender { 

int mynumber; 
mynumber = [textfieldnumber.text intValue]; 

if (mynumber==0) { 

    NSString *errorstr = [[NSString alloc] initWithFormat:@"Please, set the number of people..."]; 
    labelerror.text = errorstr; 


}else{ 
    [self performSegueWithIdentifier:identifies sender:self]; 

} 

} 

- (IBAction)calc:(id)sender { 

int mynumber; 
mynumber = [textfieldnumber.text intValue]; 

if (mynumber==0) { 

    NSString *errorstr = [[NSString alloc] initWithFormat:@"Please, set the number of people..."]; 
    labelerror.text = errorstr; 


}else{ 
    [self presentModalViewController:viewController animated:YES]; 
} 


} 
+0

我已經確定了segue爲「calcsegue」,但是出現了一個錯誤,告訴我我正在使用未聲明的標識符... – 2012-07-16 17:36:08

+0

您是指當您運行它或嘗試編譯它時? – jacerate 2012-07-16 17:36:59

+1

試圖編譯 – 2012-07-16 17:38:25

相關問題