Search code examples
iosobjective-cuiactionsheetuiactionsheetdelegate

local declaration of 'myViewController' hides instance veriable


In the action sheet delegate method im modaling to another view based on the button index, this is the method:

- (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];
    }
}

im getting the error next to the nevigationConroller declaration, does someone knows what is the problem?

im declaring MyViewController in the .h class of this class..

thanks


Solution

  • The class that contains your actionSheet:clickedButtonAtIndex: method has an ivar named myViewController. You have created a local variable also named myViewController. Your Xcode project has been told to treat this as an error instead of just a warning. Change your local variable name.

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