- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath未被调用 [英] - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is not being called
问题描述
所以它真的很奇怪...我在头文件中有一个名为ListEventsViewController的ViewController
So its really weird... I have a ViewController called ListEventsViewController
:
@interface ListEventsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *eventsTable;
@property (strong, nonatomic) NSArray *events;
@end
在实施中我称之为非常强制性的功能下面:
In the Implementation I am calling the pretty much mandatory functions below:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [events count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
cell = [eventsTable dequeueReusableCellWithIdentifier:@"eventCell"];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"eventCell"];
}
NSString *textLabelTitle = [[events objectAtIndex:indexPath.row] objectForKey:@"name"];
NSString *textLabelDetail = [[events objectAtIndex:indexPath.row] objectForKey:@"date"];
//cell.imageView.image = someimage;
NSLog(@"Text Label Title: %@", textLabelTitle);
NSLog(@"Text Label Detail: %@", textLabelDetail);
cell.textLabel.text = textLabelTitle;
cell.detailTextLabel.text = textLabelDetail;
return cell;
}
问题是函数 - (UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {未被调用,因此未填充单元格。也没有分配单元格的数量。可能导致这种情况的原因是什么?
The problem is the function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ is not being called so the cells arent being populated. also the number of cells isnt being allocated either. What could be causing this?
看起来我看到的是h和IB的图片。
It looks wired up to me heres a picture of the h and IB.
推荐答案
您在屏幕截图中说明您已将表链接到其IBOutlet,但您尚未将表视图的委托或数据源链接到控制器,因此您的表委托了诸如 cellForRowAtIndex之类的方法
将不会被调用。链接这些应该可以解决您的问题。
You illustrated in your screenshot that you have linked the table to its IBOutlet, but you haven't linked the table view's delegate or datasource to your controller and therefore your tables delegate methods such as cellForRowAtIndex
will not be called. Linking these should fix your problem.
这篇关于 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!