gpt4 book ai didi

ios - 'NSInvalidArgumentException'

转载 作者:行者123 更新时间:2023-12-01 17:58:43 26 4
gpt4 key购买 nike

我在 map 中有一些注解 View ,我希望通过touchUpInside打开一个新的ViewController,但出现此错误:

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

这是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
//....
}

最佳答案

更改

@selector(loadDetailListViewController:) 


@selector(loadDetailListViewController)

原因: @selector(abc)给出方法 abc的选择器,不带任何参数。 @selector(abc:)abc方法的选择器提供一个参数。因此, @selector(abc::)abc方法的选择器提供了两个参数对象。

Objective-C是多态的。意味着同一方法可能存在多次。这意味着它们具有相同的名称,并被多次实现以根据参数的数量(或如果在选择器语句中也给出了参数的名称,则取决于参数的名称)来提供方法的变体。

严格说出的 abcabc:abc::可能完全不同并且彼此独立。但这将是非常糟糕的风格。相当普遍的是,这些方法或多或少都具有相同的功能,并且其功能只是在细节上因传递给它的不同值而变化。

关于ios - 'NSInvalidArgumentException',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13266066/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com