无效的参数异常iOS

时间:2014-11-10 05:04:36

标签: ios objective-c uiviewcontroller

我是iOS编程的新手。我得到了一个错误,总是困扰我好几天。我尝试使用谷歌搜索它,但没有一个答案似乎工作(或者只是我没有完全理解这些东西是如何工作的。)

2014-11-10 12:45:26.858 Launchlabs Int[1502:60b] -[UIViewController buttonClicked:]: unrecognized selector sent to instance 0x8d57960 2014-11-10 12:45:26.862 Launchlabs Int[1502:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController buttonClicked:]: unrecognized selector sent to instance 0x8d57960'

我的应用代表标题:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) UIViewController *firstScrn;
@end

App Delegate实施:

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize firstScrn;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    firstScrn = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = firstScrn;

    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

ViewController h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *btn;

- (IBAction)buttonClicked:(id)sender;
-(IBAction)secondBtnClick:(id)sender;
@end

ViewController m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (IBAction)buttonClicked:(id)sender {
    NSLog(@"hello");
}

-(IBAction)secondBtnClick:(id)sender
{

}
@end

继承人我的nib文件的屏幕截图: enter image description here

1 个答案:

答案 0 :(得分:0)

在您的app delegate中修复此问题

  

//的.h

     

#import“ViewController”//导入此标题

     

// @ property(strong,nonatomic)UIViewController * firstScrn;

     

@property(强,非原子)ViewController * firstScrn;

     

//。米

     

// firstScrn = [[UIViewController alloc]   initWithNibName:@“ViewController”bundle:nil];

     

firstScrn = [[ViewController alloc] initWithNibName:@“ViewController”bundle:nil];