我正在开发一个小型应用程序,我希望应用程序一启动就显示一个警告框。我认为将代码放入viewDidLoad会导致这种情况发生,但似乎并非如此。
我想要做的是两次出现警报。第一个是第一位,第二位是第二位,现在我只是想让第一位发挥作用。
这是正确的方法,还是有更好的方法?谢谢。
- (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.
}发布于 2013-04-10 02:14:30
https://stackoverflow.com/questions/15915713
复制相似问题