简体   繁体   English

'NSInvalidArgumentException'

[英]'NSInvalidArgumentException'

I have some annotationView in the map and I want that with touchUpInside open a new ViewController but I get this error: 我在地图中有一些注解视图,我希望通过touchUpInside打开一个新的ViewController,但出现此错误:

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
 [MapViewController loadDetailListViewController:]: unrecognized selector sent 
 to instance 0xa042380'

This is the code in MapViewController.m: 这是MapViewController.m中的代码:

 -(void)loadDetailListViewController{


      if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){

    DetailListViewController *detailList =[[DetailListViewController 
    alloc]initWithNibName:@"DetailListViewController~iPhone" bundle:nil];
    detailList.title = self.chinaTable.title;
    detailList.chinaTable = self.chinaTable;


    [self.navigationController pushViewController:detailList animated:YES];

}else {

    DetailListViewController *detailList =[[DetailListViewController 
    alloc]initWithNibName:@"DetailListViewController~iPad" bundle:nil];
    detailList.title = self.chinaTable.title;
    detailList.chinaTable = self.chinaTable;

    [self.navigationController pushViewController:detailList animated:YES];
}

}

 - (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id 
    <MKAnnotation>)annotation {

       //......

     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
       [rightButton addTarget:self action:@selector(loadDetailListViewController:) 
      forControlEvents:UIControlEventTouchUpInside]; //the error is here
      //....
     }

Change 更改

@selector(loadDetailListViewController:) 

to

@selector(loadDetailListViewController)

Reason: @selector(abc) gives the selector of a method abc without any parameters. 原因: @selector(abc)给出方法abc的选择器,不带任何参数。 @selector(abc:) gives the selector of the method abc with one parameter. @selector(abc:)给出了该方法的选择abc与一个参数。 Consequentially @selector(abc::) gives the selector of the method abc with two parameter objects. 因此,@selector @selector(abc::)为方法abc的选择器提供了两个参数对象。

Objective-C is polymorph. Objective-C是多态的。 Meaning the same method may exist multiple times. 意味着同一方法可能存在多次。 That means they have the same name and are implemented multiple times to provide variations of the method depending on the number of parameters (or on the names of parameters if the names of parameters are given in the selector statement too). 这意味着它们具有相同的名称,并被多次实施以提供方法的变体,具体取决于参数的数量(或者如果在选择器语句中也给出了参数的名称,则取决于参数的名称)。

Strictly spoken abc and abc: and abc:: may be totally different and independent from each other. 严格说出的abcabc:abc::可能完全不同并且彼此独立。 But that would be very bad style. 但这将是非常糟糕的风格。 It is rather common that the methods do more or less the same and their functionality is just varied in details driven by the different values that are passed to it. 相当普遍的是,这些方法或多或少都具有相同的功能,而其功能只是在细节上因传递给它的不同值而有所变化。

在选择器中使用loadDetailListViewController而不是loadDetailListViewController:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM