【发布时间】:2017-10-28 18:20:21
【问题描述】:
我在 TableView Cell 中有一个 UIButton:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UIButton *ImageViewFavorited = (UIButton *)[cell viewWithTag:7];
[ImageViewFavorited addTarget:self action:@selector(BtnClicked:) forControlEvents:UIControlEventTouchUpInside];
}
我想在点击事件时更改此按钮的背景图像,因此我有一个与此按钮相关联的操作:
- (IBAction)BtnClicked:(id)sender {
NSLog(@"I enter in BtnClicked");
UIImage *ImageNNotFavorited = [UIImage imageNamed:@"NotFavorited"];
[sender setImage:ImageNNotFavorited];
}
运行此代码后出现以下错误:
-[UIButton setImage:]: unrecognized selector sent to instance 0x7fd19c83ea00
我不知道如何解决这个问题,你有什么想法吗?
【问题讨论】:
-
如果您将操作更改为:
- (IBAction)BtnClicked:(UIButton *)sender {,这将更容易解决。另请注意,变量和方法名称应以小写字母开头。类名以大写字母开头。
标签: ios objective-c uitableview uibutton