[英]TableView reloadData doesn't update UI in iPad , but works in iPhone
I have a strange error . 我有一个奇怪的错误。 I am using
UITableView
which has to be reloaded when a row get selected . 我正在使用
UITableView
,当选择一行时必须重新加载。 This works fine in iPhone simulator . 这在iPhone模拟器中可以正常工作。 While running in iPad ,
didSelectRowAtIndexPath
is getting called but the UI isn't getting updated . 在iPad上运行时,
didSelectRowAtIndexPath
被调用,但UI未被更新。 I tried calling the method reloadData
on main thread . 我尝试在主线程上调用方法
reloadData
。 It's still the same . 还是一样。
I have tried various solutions in stackoverflow . 我在stackoverflow中尝试了各种解决方案。 Nothing seemed to fix my issue .
似乎没有什么能解决我的问题。
UPDATE UPDATE
When i select a cell , new cell will be added . 当我选择一个单元格时,将添加新的单元格。 So i need to reload my tableview to display the dynamic change .
所以我需要重新加载表格视图以显示动态更改。 Posted my code below
在下面发布我的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
NSUInteger count=indexPath.row+1;
NSMutableArray *insertIndexPaths = [NSMutableArray array];
[insertIndexPaths addObject:[NSIndexPath indexPathForRow:count inSection:indexPath.section]];
switch (indexPath.row) {
case 0:
{
if ([ItemsInSection[indexPath.section] count]==1){
[ItemsInSection[indexPath.section] addObject:obj2];
[TabView beginUpdates];
[TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
[TabView endUpdates];
}
else {
[ItemsInSection[indexPath.section] removeAllObjects];
[ItemsInSection[indexPath.section] addObject:obj1];
[self.TabView reloadData];
}
}
break;
case 1:
{if ([ItemsInSection[indexPath.section] count]==2){
[ItemsInSection[indexPath.section] addObject:obj3];
[self.TabView beginUpdates];
[TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
[self.TabView endUpdates];
}
else
{
[ItemsInSection[indexPath.section] removeAllObjects];
[ItemsInSection[indexPath.section] addObject:obj1];
[ItemsInSection[indexPath.section] addObject:obj2];
[self.TabView reloadData];
}
}
break;
case 2: {
if ([ItemsInSection[indexPath.section] count]==3) {
[ItemsInSection[indexPath.section] addObject:obj4];
[self.TabView beginUpdates];
[TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
[self.TabView endUpdates];
}
else
{
[ItemsInSection[indexPath.section] removeObject:obj4];
[self.TabView beginUpdates];
[TabView deleteRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
[self.TabView endUpdates];
}
}
break;
default:
break;
}
}
You are reloading table view inside table view delegate, On tableview selection delegate method have their associated selection animation process. 您正在表视图委托内重新加载表视图,在表视图选择委托方法上具有关联的选择动画过程。 So I will suggest you to move all code inside this method to separate method.
因此,我建议您将此方法内的所有代码移至单独的方法。 and call that method.
并调用该方法。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
[self.aiTableView beginUpdates];
// your table view selection code
[self.aiTableView endUpdates];
});
I have found the solution for this issue . 我已经找到了解决该问题的方法。 The background color of
UITableViewCell
was set to clear colour and the background color of UIView
on the UITableViewCell
was also set to clear colour . UITableViewCell
的背景色设置为透明色, UITableViewCell
上的UIView
的背景色也设置为透明色。 Changing these settings displayed the insertion of rows in UITableView
in iPad simulator . 更改这些设置会在iPad模拟器的
UITableView
中显示行的插入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.