【发布时间】:2015-01-08 20:42:50
【问题描述】:
我将 Xcode 更新到版本 6,并将我的 iOS 应用程序的部署目标从之前的 7.0 更改为 8.1。在此更新之前,该应用程序在我的 iPad 和 iOS 模拟器上运行没有任何问题。然而,更新后,我可以像以前一样在我的设备上运行该应用程序(以前是 iOS 7,但也刚刚更新到 iOS 8.1),但它在模拟器上崩溃并出现 NSInvalidArgumentException:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell disclosureButton]: unrecognized selector sent to instance 0x7f85c7f0'
在这方面,BuildingCell 或公开按钮没有什么特别之处。但是,当我尝试向披露按钮添加操作时,应用程序崩溃了。
BuildingCell 标头:
@interface BuildingsCell : UITableViewCell
@property (strong, nonatomic) UIButton *disclosureButton;
@end
应用崩溃的函数:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BuildingCell";
BuildingsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [BuildingsCell.alloc initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryNone;
//*** App crashes on the line below ***
[cell.disclosureButton addTarget:self action:@selector(tappedCell:)forControlEvents:UIControlEventTouchUpInside];
Building *currentBuilding = self.buildingArray[indexPath.row];
return cell;
}
我尝试链接到公开按钮的功能
- (void) tappedCell:(id)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.buildingTableView];
NSIndexPath *indexPath = [self.buildingTableView indexPathForRowAtPoint:buttonPosition];
[self tableView:self.buildingTableView accessoryButtonTappedForRowWithIndexPath:indexPath];
}
我找不到代码有什么问题。是不是模拟器有问题?模拟器是否有我需要设置的参数?我有一段时间没有对 Xcode 或这个应用程序做太多事情了,我显然错过了一些东西。在这一点上,任何建议都会有所帮助,因为我不知道。
【问题讨论】:
-
不要'你需要
UITableViewCellAccessoryDetailDisclosureButton作为它崩溃的那一行上方的accessoryType吗?也许我错了或错过了什么。 -
我只是想说和lewiguez一样的话。我认为您正在尝试将事件添加到不存在的项目中。尝试将崩溃上方的行更改为 cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
-
另外,为了清楚起见,你的 alloc/init 对有 cell = BuildingsCell.alloc。第 7 行。不确定这是否是拼写错误。我还在假设,但只是想指出以防万一。
-
BuildingsCell *cell = (BuildingsCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];? -
我尝试将 cell.accessoryType 更改为 UITableViewCellAccessoryDetailDisclosureButton 但应用程序同样崩溃。
标签: objective-c ios8 xcode6