Amir
Amir

Reputation: 455

cellForRowAtIndexPath doesn't get called

I build UIView with few labels and one UITableview. the problem is that when I load the view the method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
never get called. the code:

-(void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];

  m_ShopSalesTable =[[UITableView alloc]init]; //this is the UITableView    
  m_ShopSalesTable.delegate = self; 
  m_ShopSalesTable.dataSource = self;   
  [self.view addSubview:m_ShopSalesTable];
  [m_ShopSalesTable reloadData];
}

i have put the UITableViewDelegate ,UITableViewDataSource> in the declaration of the class but nothing helped.

Upvotes: 1

Views: 743

Answers (5)

jrturton
jrturton

Reputation: 119242

As Kalle has asked in a comment on another answer, what are you returning from your numberOfSections method? In the default created from the template, I think this returns zero which has bitten me on a few occasions.

Upvotes: 0

Tim
Tim

Reputation: 11

I had the same issue where cellForRowAtIndexPath was never called. I had several issues:

  • my tableView was not connected in my .xib file
  • the data I was filling came from an http delegate callback, so I had to use performSelectorOnMainThread()
  • lastly, I was using grouped views, so my mistake was that I did not add a section to my table.

Spent about 5 hours trying to figure this out, hope it helps someone else!

Upvotes: 1

bstahlhood
bstahlhood

Reputation: 2006

You are initializing with no frame. You are doing this:

[[UITableView alloc]init];

I would do this:

[[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, *setYourWidthHere*, *setYourHeightHere*)];

Upvotes: 1

Leg10n
Leg10n

Reputation: 552

I don't see where you assign tableview to m_shopSales Try:

self.tableView=m_ShopSalesTable;

before reloadData

Also m_ShopSalesTable is leaking do a release after setting self.tableView.

Upvotes: 0

Ben Gottlieb
Ben Gottlieb

Reputation: 85522

Did you set the tableView datasource to be the class that implements the above method? Did you return a non-zero number for both -numberOfSectionsInTableView: and –tableView:numberOfRowsInSection:? Are ANY of your tableview datasource methods being called?

Upvotes: 0

Related Questions