UIAlertView与按钮链接替代ViewController

问题描述:

我需要一个按钮,导致一个UIAlertView与动作弹出。UIAlertView与按钮链接替代ViewController

一旦警报弹出,它需要有1个按钮取消并保持在同一页面上,并有1个按钮将您链接到另一个ViewController。

这是我从一些论坛拼凑在一起,但我不知道我在做什么,它给了我大约9个错误消息。请帮忙!

-(IBAction)Alert:(id)sender { 
    UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"Alert" 
               message:@"Warning! By entering the Tutorial, all data will be lost. Are you sure you want to continue?" 
              delegate:self 
            cancelButtonTitle:@"Return to Data Collection" 
            otherButtonTitles:@"Continue", nil]; 
    [Alert Show]; 
    [Alert Release]; 
} 


- (void)Alert:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if(Alert.tag==0) { 

     if(buttonIndex == 1)//OK button pressed 
     { 
      Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil]; 
      [self presentModalViewController:Info animated:YES]; 
     } 

代码的第一箱的工作原理,这样,当我按下主屏幕上的按钮,2个按钮的警告弹出。

但是,我无法获得第二个按钮来将我链接到下一个ViewController。

  1. Objective-C区分大小写。

    [Alert show]; 
    [Alert release]; 
    

    - (void)alertView:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex 
    

    (你怎么认为,它可以工作,如果重命名方法???)

  2. 删除if(Alert.tag==0) {

  3. 为什么你没有在这里传递一个nib文件的名字:Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];

  4. 请坚持编码习惯。对象在camelCase中被命名。

结论
让你一本好书或影片从一开始就学习。 Some resources这样做。

+0

用于编码约定的+1 –

+0

为nibName传递nil很好 - 它只是加载一个名称与类名相匹配的nib - 在这种情况下为Tutorial.xib。当然,如果笔尖没有被调用,那么你会遇到问题。 –