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;


    }


}
4

1 回答 1

0

从情节提要中删除 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];
}


}
于 2012-07-16T17:20:20.437 回答