0

当我尝试将具有多个参数的方法添加到按钮的选择器时,由于未捕获的异常“NSInvalidArgumentException”而出现此错误正在终止应用程序

[viewButton addTarget:self action:@selector(loadDocument:inView:) withObject:cerereIndemnizatie.fisier withObject:self.myWebview forControlEvents:UIControlEventTouchUpInside];

这是方法

  -(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

}

4

1 回答 1

1

我不知道你为什么认为你可以这样做,或者为什么会UIButton响应addTarget:selector:withObject:withObject:forControlEvents:选择器......(说真的,不要猜测,阅读文档......)

您可以通过使用关联对象来实现类似的行为:

UIButton *btn = // create the button
objc_setAssociatedObject(btn, "firstObject", someObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(btn, "secondObject", otherObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

- (void)click:(UIButton *)sender
{
    id first = objc_getAssociatedObject(btn, "firstObject");
    id second = objc_setAssociatedObject(btn, "secondObject");
    // etc.
}
于 2012-11-15T12:20:31.853 回答