首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >viewDidLoad未被调用

viewDidLoad未被调用
EN

Stack Overflow用户
提问于 2013-04-10 02:07:04
回答 1查看 540关注 0票数 0

我正在开发一个小型应用程序,我希望应用程序一启动就显示一个警告框。我认为将代码放入viewDidLoad会导致这种情况发生,但似乎并非如此。

我想要做的是两次出现警报。第一个是第一位,第二位是第二位,现在我只是想让第一位发挥作用。

这是正确的方法,还是有更好的方法?谢谢。

代码语言:javascript
复制
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"here...");
// Do any additional setup after loading the view.
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Player 1" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
[alert release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]);
}

视图控制器仅由以下方法组成:

代码语言:javascript
复制
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    BoxView* myView = [[BoxView alloc]
                      initWithFrame:[[UIScreen mainScreen] bounds]];
    self.view = myView;
    [myView release];
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
EN

回答 1

Stack Overflow用户

发布于 2013-04-10 02:14:30

问题是viewDidLoad太早了。还没有接口!至少要等到viewDidAppear:

请看我在这里的类似回答:

https://stackoverflow.com/a/15867468/341994

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15915713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档