如果按钮无法前进到另一个视图

时间:2012-07-16 17:02:23

标签: objective-c xcode

我希望当用户在文本字段中输入一个数字时,这个数字将用于大量操作,但是这个数字不能为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;


    }


}

1 个答案:

答案 0 :(得分: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];
}


}