不会调用cellForRowAtIndexPath

时间:2010-08-29 16:44:18

标签: iphone objective-c

我使用少量标签和一个UITableview构建UIView。问题是当我加载视图方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath时 永远不会被打电话 代码:

-(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];
}

我放了UITableViewDelegateUITableViewDataSource>在班级宣言中 但没有任何帮助。

5 个答案:

答案 0 :(得分:1)

您正在初始化时没有框架。你这样做:

[[UITableView alloc]init];

我会这样做:

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

答案 1 :(得分:1)

我遇到了同样的问题,即从未调用过cellForRowAtIndexPath。 我有几个问题:

  • my tableView未在我的.xib文件中连接
  • 我填写的数据来自http委托回调, 所以我不得不使用performSelectorOnMainThread()
  • 最后,我正在使用分组视图,所以我的错误就是这样 我没有在我的桌子上添加一个部分。

花了大约5个小时试图解决这个问题,希望它有所帮助 别人!

答案 2 :(得分:0)

您是否将tableView数据源设置为实现上述方法的类?你是否为-numberOfSectionsInTableView:和-tableView:numberOfRowsInSection返回了一个非零数字:?是否有任何tableview数据源方法被调用?

答案 3 :(得分:0)

我没看到你将tableview分配给m_shopSales的地方试试:

self.tableView=m_ShopSalesTable;

之前reloadData

在设置self.tableView后,m_ShopSalesTable也会泄漏。

答案 4 :(得分:0)

由于Kalle在评论中提出了另一个答案,您从numberOfSections方法返回了什么?在从模板创建的默认值中,我认为这会返回零,这在某些情况下会让我感到困惑。