TableView not reloading

谁都会走 提交于 2020-03-26 02:37:26

问题


I am designing a one-to-one chatting interface using table view. This table view is modified to show bubbles as some new message arrives. The new message arrives through a push-notification in this case. I call following code in my function which receives message through the push notification:

-(void)messageReceived: (NSString *)message{
    _message=[message retain];
    [tableView reloadData];
}

However, it seems this does not reload my table view. If I place the call for reloadData in the viewDidAppear function, it reloads fine. It also reloads fine, if I place the reloadData call in a function whose return type is IBAction (ex: a function binding to button click)

What could be the reason for reloadData to not get triggered through custom declared functions ?


回答1:


reloaddata method is called but the trick here that you didn't add the incoming message to the datasource that the tableview load from !




回答2:


may be you have not Connect the Tableview with table view Delegates and Datasource

Objective-C

@interface YourClass : UIViewController <UITextFieldDelegate, UITextViewDelegate>

yourtableview.delegate = self;
yourtableview.dataSource = self;

[tableView reloadData];

Swift 3

class YourClass: UIViewController , UITableViewDelegate, UITableViewDataSource
yourtableview.delegate = self
yourtableview.dataSource = self

yourtableview.reloadData()

the other way is! for Swift and Objective-C both. Right Click on the Table view and drag and drop the delegates.



来源:https://stackoverflow.com/questions/16681525/tableview-not-reloading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!