简体   繁体   English

tableview insertRowsAtIndexPaths不适用于ViewdidLoad

[英]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.

相关问题 TableView的insertRowsAtIndexPaths添加了错误的名称 - TableView's insertRowsAtIndexPaths adds wrong name tableView cellForRowAtIndexPath:在ViewDidLoad之前运行? - tableView cellForRowAtIndexPath: runs before ViewDidLoad? 以编程方式添加tableView,未调用viewDidLoad - Programatically adding a tableView, viewDidLoad not called 在viewDidLoad中调用TableView:didSelectRow:AtIndexPath - Call TableView:didSelectRow:AtIndexPath in viewDidLoad 当我调用[tableView insertRowsAtIndexPaths:withRowAnimation:]时,在iOS10中崩溃 - When I called [tableView insertRowsAtIndexPaths: withRowAnimation:], crashed in iOS10 为什么insertRowsAtIndexPaths总是导致TableView滚动到顶部? - Why does insertRowsAtIndexPaths always cause the TableView to scroll to the top? insertRowsAtIndexPaths不起作用,索引超出范围的对象崩溃了吗? - insertRowsAtIndexPaths Not Working, Crashing With Object At Index Out Of Bounds? UIPopoverController和UITapGestureRecognizer在ViewDidLoad中不起作用 - UIPopoverController and UITapGestureRecognizer not working in ViewDidLoad 如果在viewDidLoad中实例化,则UITextFieldDelegate不起作用 - UITextFieldDelegate not working if instantiated in viewDidLoad UIViewController类别不适用于viewDidLoad - UIViewController category not working on viewDidLoad
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM