Uitableview重新加载问题,最初它是空的

时间:2017-09-15 02:58:34

标签: ios uitableview

假设我有一个显示消息的UITableview。让我们说最初它是空的。

现在我写第一条消息并致电[tableview reloadData]。但是消息(第一个自定义单元格)直到我向下滚动桌面视图才会显示!!!第二个或任何后续消息不存在此问题。当tableview为空时,只有第一个。

这是我的tableview布局:

msgList = [[UITableView alloc] init];
msgList.frame = CGRectMake((self.view.frame.size.width - MIN(self.view.frame.size.width, 700))/2, grpMsg.frame.size.height+10, MIN(self.view.frame.size.width, 700), self.view.frame.size.height-grpMsg.frame.size.height-10);

msgList.delegate = self;
msgList.dataSource = self;

if (self.view.frame.size.width <= 700) {
    msgList.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
} else {
    msgList.autoresizingMask = UIViewAutoresizingFlexibleHeight;
}
[msgList visibleCells];
[msgList indexPathsForVisibleRows];
msgList.backgroundColor = [UIColor clearColor];
msgList.separatorStyle = UITableViewCellSeparatorStyleNone;
msgList.keyboardDismissMode  = UIScrollViewKeyboardDismissModeInteractive;
msgList.estimatedRowHeight = 80;
msgList.contentInset = UIEdgeInsetsMake(56.0, 0.0, 0.0, 0.0);
msgList.scrollIndicatorInsets = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
msgList.transform = CGAffineTransformMakeScale(1, -1); // flip tableView upside down
msgList.backgroundColor = [UIColor colorWithRed:200/255.0f green:255/255.0f blue:255/255.0f alpha:1.0];
[self.view addSubview:msgList];

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

发送消息后,获取新数据并致电[tableView reloadData];我还必须致电:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    msgList.contentInset = UIEdgeInsetsMake(MAX(keyboardHeight+12, msgList.frame.size.height - msgList.contentSize.height), 0, 0, 0);
});

...到(我猜)刷新布局。问题消失了。