我需要动态插入行动画&它在按钮水龙头上正常工作。 但是当我在收到推送通知后在ViewDidLoad方法上实现它时,它就无法正常工作。
以下是代码:
[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];
答案 0 :(得分:0)
请尝试这个。它可能对你有所帮助
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];
});
答案 1 :(得分:0)
使用此代码ViewDidLoad()
[self performSelector:@selector(insertRow) withObject:nil afterDelay:4];
然后
-(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];
});
}