不会调用UITableView委托和dataSource方法 [英] UITableView delegate and dataSource methods not getting called
问题描述
我有一个包含UITableView的UIView。 tableview的委托设置为我的UIView,但它从不调用委托方法:
I have a UIView which contains a UITableView. The tableview's delegate is set to my UIView, but it never calls the delegate methods:
-(id)init {
self = [super init];
if (self) {
self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.scrollEnabled = NO;
self.tableView.layer.cornerRadius = PanelCornerRadius;
[self addSubview:self.tableView];
}
return self;
}
#pragma mark - UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"height for row");
int height = [self heightForRowAtIndexPath:indexPath];
return height;
}
#pragma mark - UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"number of rows");
if (self.manager.fetchOperation.dataFetchProblem) {
return 1;
}
int numberOfRows = [self.delegate numberOfSectionsInPanel:self];
return numberOfRows;
}
我已经探索过我能想到的每一个选项,但似乎无法找到问题的根源。
I've explored every option I can think of, but can't seem to find the root of the problem.
编辑:包含numberOfRowsInSection。它可能会返回0,只有它永远不会有机会,因为行数NSLog永远不会被调用。
Included the numberOfRowsInSection. It could potentially return 0, only it never gets that chance because the "number of rows" NSLog never gets called.
推荐答案
可以你能写一下你在cellForRowAtIndexPath:方法上写的代码吗?因为我发现你的代码没有任何问题。
Can you please write the code that you have written on your cellForRowAtIndexPath: method? Because i can't find anything wrong with your code.
您是否从其他ViewController调用UIView?如果是,怎么样?
Are you calling your UIView from some other ViewController? If yes, how?
我做过类似的事情一次。我在UIView中声明了一个方法:
I have done something like this once. I declared a method in the UIView like this :
- (void)setUpTableView{
self.tableview.delegate=self;
self.tableview.dataSource=self;
}
然后我从视图控制器调用了setUpTableView我将此视图添加到,像这样:
And then i called the setUpTableView from the view controller i added this view to, like this :
[self.yourView setUpTableView];
这可能有所帮助。谢谢。
This might help. Thanks.
这篇关于不会调用UITableView委托和dataSource方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!