对于我的应用程序,我需要用户输入一个数字,所以为了防止他们不输入数字,我创建了一个if/else语句,如果他们不会向用户显示错误消息不填写该字段,并在应用程序的主视图中填入数字。唯一的问题是,每当它尝试运行代码来调出下一个屏幕时,我都会崩溃。有条件地切换UIViewController
- (IBAction)budgetButton:(id)sender
{
myBudget = [self.budgetTextField.text floatValue];
NSLog(@"myBudget = %.2f", myBudget);
if (myBudget == 0)
{
self.whatsYourBudgetLabel.text = [NSString stringWithFormat:(@"You must enter a budget!")];
}
else
{
ViewController * nextView = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
self.view.window.rootViewController = nextView;
}
}
这是不连贯的。 “我需要用户输入一个数字,所以为了防止这种情况发生”您试图阻止您需要发生的事情?你能否编辑更清楚地解释你的问题?如果您的应用程序崩溃,请包含任何错误消息。 –
尝试用'[self presentViewController:nextView animated:NO completion:nil]替换'self.view.window.rootViewController = nextView;'' – GoGreen