objective-c - 带有链接备用 ViewController 的 Button 的 UIAlertView

标签 objective-c ios cocoa-touch uiviewcontroller uialertview

我需要一个按钮来弹出带有操作的 UIAlertView。

一旦警报弹出,它需要有 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. 请遵守编码约定。对象以驼峰命名。

结论
给你一本好书或视频,让你从头开始学习。 Some resources这样做。

关于objective-c - 带有链接备用 ViewController 的 Button 的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8996990/

相关文章:

ios - 如何在自定义 iOS 应用程序扩展中关闭横向?

iphone - 条码 SDK 支持 iPhone 的一维码、二维码、数据矩阵等

ios - 如何在swift中使用后台线程?

objective-c - performSelector 方法有什么作用?

objective-c - NSMenuItem 中的 NSTextField

ios - Objective-C框架的条件编译

ios - UITableViewCell 重新加载带有图案图像的选定图像

ios - 从 AppDelegate 显示/隐藏 UIAlertController

ios - 从应用委托(delegate)调用 UIViewController 方法

ios - 自动续订订阅和非消耗性 IAP