[英]tableview insertRowsAtIndexPaths not working on ViewdidLoad
I need to insert row dynamically with row animation & it's working fine on button tap. 我需要使用行动画动态插入行,并且在点击按钮时效果很好。 But when i implemented it on ViewDidLoad method after receive push notification then it is not working.
但是当我在收到推送通知后在ViewDidLoad方法上实现它时,它不起作用。
Below is code : 下面是代码:
[array_messages addObject:[messageInfo valueForKey:@"message"]];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array_messages count]-1 inSection:0];
messageFromTop=YES;
[self.tableViewMessage insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
Please try this one. 请试试这个。 Its may be helpful to you
它可能对您有帮助
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array_messages count]-1 inSection:0];
messageFromTop=YES;
[self.tableView beginUpdates];
[self.tableDatalist insertObject:obj atIndex:indexPath];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
});
use this code ViewDidLoad() 使用此代码ViewDidLoad()
[self performSelector:@selector(insertRow) withObject:nil afterDelay:4];
then 然后
-(void)insertRow
{
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array_messages count]-1 inSection:0];
messageFromTop=YES;
[self.tableView beginUpdates];
[self.tableDatalist insertObject:obj atIndex:indexPath];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.