uitableview cellforrowatindexpath not called but n

2020-07-18 10:52发布

in my tableview no of rows in section method is called and it returns value 17,but the cellforrowatindexpath is not getting called.i have put breakpoints in the first line of this method but this point is never shown when debugging,i have followed the tableviewdelegate and datasource.and the tableviews datasource,delegate are properly set in the Int builder.

i am also posting some of the code

in my viewcontroller.m

-(void)viewDidLoad
{

        tweets=[[NSMutableArray alloc]init];
        [self updateStream:nil];
        [self.tweetsTable setDelegate:self];
        [self.tweetsTable setDataSource:self];

}


-(NSInteger)tableView:(UITableView *)tweetsTable numberOfRowsInSection:(NSInteger)section {

    return [tweets count];

}

-(UITableViewCell *)tableView:(UITableView *)tweetsTable cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"twitCell";
    TwitCell *cell = (TwitCell *)[tweetsTable dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = (TwitCell *)[[[TwitCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];   
    }
    cell.tweet = [tweets objectAtIndex:indexPath.row];
    [cell layoutSubviews];
    return cell;
}

8条回答
够拽才男人
2楼-- · 2020-07-18 11:47

check this

or else use viewDidLoad code in viewWillAppear

查看更多
疯言疯语
3楼-- · 2020-07-18 11:49

In my cases I had created a UITableView as a property on my view controller, but I forgot to add it as a subview to self.view

Strangely you will get the symptoms that sujith described: numberOfRowsInSection will be called, but cellForRowAtIndexPath will not!

This was my missing line:

[self.view addSubView:self.myTableViewProperty];

And to defend against it:

NSAssert(self.myTableViewProperty.superview != nil, @"The table view dose not have a superview");
[self.myTableViewProperty reloadData];
查看更多
登录 后发表回答