'ViewController'的本地声明隐藏了实例变量

时间:2015-02-12 16:42:17

标签: ios objective-c uiactionsheet uiactionsheetdelegate

在动作表委托方法中,我根据按钮索引模拟到另一个视图,这是方法:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) {
        NSLog(@"first button was pressed");
    } else if (buttonIndex == 1) {
        MyViewController *myViewController = [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
        UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:myViewController];
        [self.navigationController presentViewController:navigationController animated:YES completion:nil];
    }
}

即时收到nevigationConroller声明旁边的错误,是否有人知道问题是什么?

我在这个类的.h类中声明MyViewController ..

感谢

1 个答案:

答案 0 :(得分:1)

包含actionSheet:clickedButtonAtIndex:方法的类有一个名为myViewController的ivar。您已创建一个名为myViewController的本地变量 。您的Xcode项目已被告知将此视为错误,而不仅仅是警告。更改本地变量名称。

MyViewController *myVC = [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:myVC];
[self.navigationController presentViewController:navigationController animated:YES completion:nil];