我正在开发一个小型应用程序,我希望在应用程序启动后立即显示一个警报框。我认为将代码放入 viewDidLoad 会导致这种情况发生,但似乎不是。
我希望能够做的是两次出现警报。第一个将用于玩家 1,第二个用于玩家 2。现在我正在努力让第一个工作。
这是解决此问题的正确方法还是有更好的方法?谢谢。
- (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]);
}
视图控制器仅包含以下方法:
- (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.
}