【问题标题】:App crashes on users devices while loading or reloading uitableview加载或重新加载 uitableview 时应用程序在用户设备上崩溃
【发布时间】:2015-04-03 13:51:06
【问题描述】:

我正在尝试修复无法在我们的任何测试设备上重现的 chrash。该应用程序崩溃了很多次(60k 次),因为这些都在 crashlytics 上报告。在 crashlytics 中以不同方式报告相同的崩溃。但我认为两者都是一样的。

崩溃 1

崩溃 2

两次崩溃属于同一类型。

我有 2 个不同的委托方法在链上触发。

第一个委托方法有以下代码,该方法由 UITableviewcell 实现。

- (void)flightSegment:(FlightSegmentViewController *)flightSegmentController didChangeHeightWith:(CGFloat)heightDelta {
int index = [flightSegmentControllers indexOfObject:flightSegmentController];   //Shows warning as indexOfObject returns NSUInteger rather than int. Could this be the problem? if it is then it should crash in all the devices. 

[UIView beginAnimations:@"originAndDestinationAnimation" context:nil];
[UIView setAnimationDuration:0.3f];

for (int i = index + 1; i < flightSegmentControllers.count; i++) {
    FlightSegmentViewController *vc = [flightSegmentControllers objectAtIndex:i];
    CGRect frame = vc.view.frame;
    frame.origin.y += heightDelta;
    vc.view.frame = frame;
}
[UIView commitAnimations];

[delegate bookingCell:self didChangeHeightWith:heightDelta];

}

第二个委托方法有以下代码。这个委托方法是由实际的 TableViewContoller 实现的。

- (void)bookingCell:(XXXGMBookingCell *)theBookingCell didChangeHeightWith:(CGFloat)heightDelta {
[menuTableView beginUpdates];
[menuTableView endUpdates];

[self performSelector:@selector(reloadData) withObject:menuTableView afterDelay:0.333f];

}

有人可以指导这是崩溃的地方吗?我的主要意图是在我的测试设备上重现该问题,然后尝试修复它。

编辑

- (void)disruptionBannerShow {
NSInteger numOfRowsInSectionNul = [self tableView:menuTableView numberOfRowsInSection:0];
if (numOfRowsInSectionNul == 0) {
    [menuTableView beginUpdates];
    NSArray *insertedRows = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]];
    [menuTableView insertRowsAtIndexPaths:insertedRows withRowAnimation:UITableViewRowAnimationTop];
    [menuTableView endUpdates];
}
[self performSelector:@selector(reloadData) withObject:menuTableView afterDelay:0.33333f];

}

还有

- (void)disruptionBannerHide {
NSInteger numOfRowsInSectionNul = [self tableView:menuTableView numberOfRowsInSection:0];
if (numOfRowsInSectionNul > 0) {
    [menuTableView beginUpdates];
    NSArray *deletedRows = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]];
    [menuTableView deleteRowsAtIndexPaths:deletedRows withRowAnimation:UITableViewRowAnimationTop];
    [menuTableView endUpdates];
}
[self performSelector:@selector(reloadData) withObject:menuTableView afterDelay:0.33333f];

}

我几乎没有其他地方可以插入和删除某些东西。任何人都可以在我的编辑中看到错误。

【问题讨论】:

    标签: ios uitableview delegates reloaddata


    【解决方案1】:

    发生崩溃是因为您对表格的更新不正确。 崩溃表明部分中的行数不匹配。将代码发布到您将单元格添加到部分或删除它们的位置。删除/添加行后,您的函数 numberOfRowsInSection 再次被调用,您将在其中返回旧计数。

    【讨论】:

    • @Rajashekar 我希望你不要为此感到沮丧。但是人们很难在你的逻辑中看到错误。每次删除/更新后,请确保您的 numberOfRowsInSection 也会返回正确的值。在代码中放置断点并确保值正确与否。
    猜你喜欢
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 2015-02-24
    相关资源
    最近更新 更多