我正在开发一个应用程序,用户应该能够使用按下行时显示/隐藏的UIDatePicker设置开始和停止时间。我通过在触摸行下方插入UIDatePicker来实现此目的。当我在模拟器中运行应用程序时,一切都运行顺畅而且很好,但是当我在真实设备上试用它时,UIDatePicker出现大约需要2秒钟。选择器加载速度很慢" start"并且"停止"时间一次,但在此之后,当再次显示/隐藏它时,它将恢复到正常加载时间。我想知道这里可能出现什么问题。
这是didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == dataSection) {
if ((indexPath.row != self.pickerIndexPath.row && self.pickerIndexPath != nil) || self.pickerIndexPath == nil) {
[self togglePicker:indexPath]; //<--- This one takes up to two seconds
}
}
else if (indexPath.section == buttonSection && indexPath.row == 0) {
[self registerTime];
}
}
这是togglePicker:
- (void)togglePicker: (NSIndexPath *)indexPath {
[self.tableView beginUpdates];
NSArray *indexPathArray;
if (self.pickerIndexPath != nil) {
//Should remove old one first
NSArray *indexPathArray = @[[NSIndexPath indexPathForRow:self.pickerIndexPath.row inSection:dataSection]];
[self.tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade];
}
if (indexPath.row + 1 != self.pickerIndexPath.row) {
NSInteger rowDiff = 1;
if ([self isUnderPicker:indexPath]) {
rowDiff = 0;
}
indexPathArray = @[[NSIndexPath indexPathForRow:indexPath.row + rowDiff inSection:dataSection]];
// --- These two lines below seems to have something to do with it
// --- because if I comment these out the application never get stuck (otherwise 2 seconds)
[self.tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade];
self.pickerIndexPath = [NSIndexPath indexPathForRow:indexPath.row + rowDiff inSection:dataSection];
}
else {
self.pickerIndexPath = nil;
}
[self.tableView endUpdates];
[self givePickerStandardValues];
}
在cellForRowAtIndexPath中,我只是简单地返回这个,但是我认为这不应该是一个问题:
newCell = [tableView dequeueReusableCellWithIdentifier:pickerCellID];
任何想法会在第一次出现的情况下导致真实设备上的拾取时间过长?非常感谢你!