Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 按UIBarButtonItem时发送到instance+崩溃的无法识别的选择器_Ios_Objective C - Fatal编程技术网

Ios 按UIBarButtonItem时发送到instance+崩溃的无法识别的选择器

Ios 按UIBarButtonItem时发送到instance+崩溃的无法识别的选择器,ios,objective-c,Ios,Objective C,我将NSException unrecognized选择器发送到实例,然后每当按下btnReload UIBarButtonItem时,我的应用程序就会崩溃。我包含了该方法对操作执行的操作的代码,但是无论testChangingViewController方法是否包含代码,都会发生崩溃/异常 以下所有代码都在我的UIViewController类中 - (void)loadView //use loadView because not a storyboard based GUI. {

我将NSException unrecognized选择器发送到实例,然后每当按下btnReload UIBarButtonItem时,我的应用程序就会崩溃。我包含了该方法对操作执行的操作的代码,但是无论testChangingViewController方法是否包含代码,都会发生崩溃/异常

以下所有代码都在我的UIViewController类中

- (void)loadView //use loadView because not a storyboard based GUI.
{
    [super loadView];

    UIBarButtonItem *btnReload =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(testChangingViewController:)];
    self.navigationController.topViewController.navigationItem.leftBarButtonItem = btnReload;
    btnReload.enabled=TRUE;

    //self.view = [[UIView alloc] initWithFrame:[[UIScr een mainScreen] bounds]];
    [self.view setBackgroundColor:[UIColor whiteColor]];

    [self setTitle:@"Navigation"]; //navigation bar title tied to the view controller it is managing.

    UIImageView *friendsIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"change_user-512"]];
    [friendsIcon setFrame:CGRectMake(60, 130, 70, 70)];
    [self.view addSubview:friendsIcon];

    UIImageView *statusIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"talk-512"]];
    [statusIcon setFrame:CGRectMake(180,130, 70, 70)];
    [self.view addSubview:statusIcon];

    UIView *square = [[UIView alloc] initWithFrame:CGRectMake(250, 250, 50, 50)];
    [square setBackgroundColor:[UIColor orangeColor]];
    [self.view addSubview:square];
    // Do any additional setup after loading the view.
}



-(void)testChangingViewController
{
    UITableViewController *newViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    [self.navigationController pushViewController:newViewController animated:YES];
}

您可以将@selectortestChangingViewController:colon作为一个参数分配给UIBarButtonItem,但您可以定义方法testChangingViewController无冒号,无参数。它正在查找的接受参数的选择器不存在,因此您会出错。这些目标选择器总是倾向于有一个参数,发送者,即生成事件的UIControl。

您应该发布整个错误消息,但您的错误是明显的-您说选择器应该是testChangingViewController:带有冒号,但您实现了testChangingViewController方法,没有冒号,-1因为没有包含准确的错误消息。啊,谢谢你,先生。我在哪里可以了解有关ios中不同类型事件的更多信息?这些目标选择器总是倾向于有一个参数,发送者,即生成事件的UIControl。我为什么需要这个?不客气!我为选票和支票而活;该参数非常有用,因为您可以有多个按钮或控件,这些按钮或控件都具有与其操作相同的选择器。然后在该方法中,您可以检查哪个控件生成了事件,并执行不同的操作。签出中常量下的uicontrol事件