【问题标题】:app crashes on simulator 8 but not on device应用程序在模拟器 8 上崩溃,但在设备上没有
【发布时间】: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 = UITableViewCellAccessoryDe​​tailDisclosureButton;
  • 另外,为了清楚起见,你的 alloc/init 对有 cell = BuildingsCell.alloc。第 7 行。不确定这是否是拼写错误。我还在假设,但只是想指出以防万一。
  • BuildingsCell *cell = (BuildingsCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];?
  • 我尝试将 cell.accessoryType 更改为 UITableViewCellAccessoryDe​​tailDisclosureButton 但应用程序同样崩溃。

标签: objective-c ios8 xcode6


【解决方案1】:

哇。 . .所以我在我的应用程序中发现了这个问题。这与我的预期相去甚远。

问题实际上是本地化问题之一。我的应用程序是法语的,但我有一个不完整的英语故事板(早期尝试使应用程序双语),很久以前就搁置了。因此,尽管我将模拟器的语言设置为法语,但每次应用程序在模拟器上运行时,它都会使用不完整的英语故事板。我没有注意到,由于崩溃,只有初始视图(不包含语言区分信息)是可见的。

Xcode 6 似乎进行了一些本地化更新。

我通过在编辑方案中将应用程序语言设置为“法语”解决了这个问题。

所以你。 .现在感觉有点害羞。

感谢您的建议。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多