'NSObject'可能无法响应-navigationController

时间:2011-04-26 04:33:18

标签: iphone objective-c xcode uiviewcontroller navigationcontroller

您好,我目前在一行代码上发出警告,我正在尝试将新视图推送到屏幕上。 大纲//我的NSObject从我设置的服务器收到代码= 1。一切正常,代码通过然后初始化一个AlertView,我已经设置了一个if语句来捕获我的AlertView消息的按钮单击。当按下该按钮时,我的应用程序就会崩溃。

我已经声明了我正在尝试推送其头文件的视图的ViewController,并且在编译时没有错误警告。

这是我制作的NSObject

    /////.h
    #import <Foundation/Foundation.h>


@interface alerts : NSObject {

}

- (void)pleaseRegisterDevice;

@end


/////.m
#import "alerts.h"
#import "instaCode1_3AppDelegate.h"
#import "RegisterDeviceViewController.h"


@implementation alerts

//use this alert when phone falls out of sync
- (void)pleaseRegisterDevice {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
                                                    message:@"click OK to register"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];

    [alert autorelease];
    [alert show];

}


//Catch pleaseRegisterDevice method
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"OK"]) {
        NSLog(@"msg from alertView method");

        //open new wndow

        RegisterDeviceViewController *regViewController = [[RegisterDeviceViewController alloc] init];


        //Push it onto the top pf the navigation controller's stack
        **[[self navigationController] pushViewController:regViewController animated:YES];**



    }
    else {
        NSLog(@"was not able to push view");
    }

}

- (void)dealloc {
    [super dealloc];
}
@end

我在代码行中加粗了警告“警报”可能无法响应-navigationController

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:2)

我不认为NSObject子类有UINavigationController ... 您需要获得指向您的app delegate的导航控制器的指针,如此

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController pushViewController:regViewController animated:YES];

答案 1 :(得分:0)

navigationControllerUIViewController上定义的属性。 NSObject没有此方法。

答案 2 :(得分:0)

您没有任何名为navigationController的实例成员或方法,因此警告。

相关问题