Reload tableview inside a UIview

家住魔仙堡 提交于 2020-01-22 03:58:05

问题


My table view is inside a UI View, this has been done writing codes, now i am trying to reload the data in table view but the table view is not refreshing.

The UIview and the table view declaration are as follows:

@interface
{
 IBOutlet UITableView *tabView;
}

@property (nonatomic, strong) IBOutlet * tabView
@property (nonatomic, strong) UIView * myView;   // in .m file

回答1:


Provided you have linked up the delegate and the data source methods of the table view correctly, you could just do :

[self.tableView reloadData];

Make sure you have done :

self.tableView.dataSource = self;



回答2:


Ok there could be various mistakes which lead to your problem. First of all do you implement the datasource and delegate methods ?

To do so you should declare your header like this:

@interface MyClass : UIViewController<UITableViewDelegate, UITableViewDataSource> {}

Second you should hook up your tableView with those delegate/datasource methods. To do so drag&drop it in the InterfaceBuilder or in you viewDidLoad method write this:

tableView.delegate = self;
tableView.dataSource = self;

Now make sure to implement all the necessary methods:

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {}
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {}
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}

If you done all this you should update your tableView like so:

[tableView reloadData];

Also check if you connected your IBOutlet UITableView *tableView; in the Interface Builder.



来源:https://stackoverflow.com/questions/27604585/reload-tableview-inside-a-uiview

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