加载或重新加载时,应用程序在用户设备上崩溃uitableview
问题描述:
我试图修复在我们的任何测试设备上都无法重现的chrash。该应用程序崩溃无数次(60K次),因为这些正在报道crashlytics。在crashlytics中,同样的崩溃报告有所不同。但我认为两者都是一样的。加载或重新加载时,应用程序在用户设备上崩溃uitableview
崩溃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];
}
我很少有其他地方的我正在插入&删除的东西。任何人都可以在我的编辑中看到错误。
答
发生崩溃是因为您的表更新不正确。 崩溃说明某一节中的行数不匹配。将代码添加到部分或删除部分的代码。删除/添加行后,您的函数numberOfRowsInSection
再次被调用,您将返回旧计数。
请看我的编辑 – Rajashekar 2015-04-03 14:19:04
@Rajashekar我希望你不要因此而感到沮丧。但是人们很难在你的逻辑中看到错误。每次删除/更新后,确保您的numberOfRowsInSection也会返回正确的值。 在您的代码中添加断点并确保值正确与否。 – 2015-04-03 14:20:45