【发布时间】:2014-02-15 20:25:39
【问题描述】:
对于我的应用,我需要用户输入一个数字,因此为了防止他们不输入数字,我创建了一个 if/else 语句,如果用户不填写,则会向他们显示错误消息字段,如果他们填写了数字,则移动到应用程序的主视图。唯一的问题是,每当它尝试运行代码以调出下一个屏幕时,我都会崩溃。
- (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;
标签: ios objective-c uiviewcontroller