我只是在按下警报视图的第一个按钮时尝试这样做,另一个UIView出现了。
到目前为止,我已经完成了这项工作,但按下按钮后我得到的只是黑屏。第二个UIView称为ResultsViewController。
我哪里错了?任何帮助表示赞赏!
在顶部:
@class ResultsViewController;
ResultsViewController *ResultsviewController;
然后:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:ResultsviewController animated:YES completion:nil];
}
if(buttonIndex == 1){
[self startRunning];
}
}
答案 0 :(得分:1)
这两行只是创建一个UIViewController
UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:ResultsviewController animated:YES completion:nil];
你需要
ResultsViewController * ResultsviewController = [[ResultsViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:ResultsviewController animated:YES completion:nil];
答案 1 :(得分:0)
你宣告ResultsViewController *ResultsviewController;
,然后你再做一次:
UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
为什么这样做的理由? 您不必调用initWithNibName:bundle:如果您不提供nib名称。 替换此行:
UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
与那一个:
UIViewController *ResultsviewController = [[UIViewController alloc] init];
//your code to present result view controller
// EXTENDED
尝试将两行移动到新方法,例如:
-(void)openNewView {
UIViewController *ResultsviewController = [[UIViewController alloc] init];
[self presentViewController:ResultsviewController animated:YES completion:nil];
}
并在点击按钮时延迟调用它:
[self performSelector:@selector(openNewView) withObject:nil afterDelay:0.5];