I have a viewcontroller, and implement the delegate UITableViewDelegate and UITableViewDataSource, so I have following method:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_nameArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"name";
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableIdentifier = @"TableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier]autorelease];
}
UILabel *nameLabel = [[UILabel alloc] init];
nameLabel.textAlignment = UITextAlignmentLeft;
nameLabel.text = @"100";
nameLabel.backgroundColor = [UIColor blackColor];
nameLabel.textColor = [UIColor yellowColor];
[cell.contentView addSubview:nameLabel];
[nameLabel release];
return cell;
}
I set a breakpoint for each method, I can find
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
and
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
never called,but the other two methods can be called. so what’s the problem? thank you.
update:
I have connect datasoucre and delegate to file’s owner in IB,but can’t solve the problem.
_nameArray have the 0 objects that’s why it’s not coming cellForRowAtIndexPath, because if _nameArray is nil or 0 objects delegate method numberOfRowsInSection returns 0 and it’s not coming in both of the above mentioned methods.
For quick check you can return harcoded value say 10 from method numberOfRowsInSection and then see, it will call the cellForRowAtIndexPath method.