在Segue之前检查文本字段

时间:2013-12-11 00:08:13

标签: objective-c

我试图通过检查文本字段来填写Segue,因为它们是空的,如果是,它应该打印错误消息,但是当我尝试时我收到此错误消息:

控制达到非空函数的结束

问题是什么,我在苹果文档中找到了这个方法

我的代码:

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)segue sender:(id)sender {

    if ([HomeTeam.text length] != 0 && [HomePlayers.text length] != 0 && [AwayPlayers.text length] != 0 && [AwayTeam.text length] != 0) {
        NSString *errorMessage = @"You did not fill in all the fields";
        errorLabel.text = errorMessage;
    }

}

1 个答案:

答案 0 :(得分:1)

您需要从此方法返回一个值。例如:

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)segue sender:(id)sender {

    if ([HomeTeam.text length] != 0 && [HomePlayers.text length] != 0 && [AwayPlayers.text length] != 0 && [AwayTeam.text length] != 0) {
        NSString *errorMessage = @"You did not fill in all the fields";
        errorLabel.text = errorMessage;
        return NO; // need a user input: don't perform the segue
    }

    return YES; // check successful; perform segue
}