【问题标题】:ReloadData doesn't fire cellForRowAtIndexPathReloadData 不会触发 cellForRowAtIndexPath
【发布时间】:2011-03-22 09:59:14
【问题描述】:

我知道这个问题已经被问了一遍又一遍。我已经尝试了所有给定的解决方案,但仍然没有用。我已将数据源和委托设置为我的表格视图,并将其设置为我的指针。

这是我的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
NSLog(@"%i", resultSoap.count);
return resultSoap.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell.

NSString *cellValue = [resultSoap objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
NSLog(@"Celldisplay");

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

我在viewDidLoad: 方法上调用了reloadData。问题是,它触发了numberOfRowsInSection: 方法,我得到了正确的行数,但它没有触发这个cellForRowAtIndexPath: 方法。

有什么办法吗?

【问题讨论】:

  • 返回多少行?调试模式下,能看到resultSoap的内容吗?

标签: objective-c ios uitableview tableview reloaddata


【解决方案1】:

使用此代码:

urtableview.delegate = self;
urtableview.datasource = self;

在代码中声明 resultsoap 数组之后。

【讨论】:

    【解决方案2】:

    一定是表视图数据源数组"resultsoap"为空时调用了表的reload方法。 确保您的数据源数组不为空,并检查该数组是否保存了对象。

    因为如果 numberOfRowsInSection 返回 0,则可能不会调用 cellForRowAtIndexPath。 这一定是你的情况。

    【讨论】:

      【解决方案3】:

      请在您合适的方法中添加波纹管代码。

      如果你使用简单控制器并添加表格视图而不是

      在你的头文件.h中

      #import <UIKit/UIKit.h>
      @interface TaskAndTax : UIViewController<UITableViewDelegate, UITableViewDataSource>
      {
          IBOutlet UITableView *MyTableView;
      }
      @property (nonatomic, retain) UITableView *MyTableView;
      @end
      

      在你的 .m 文件中

      @synthesize MyTableView;
      
      -(void) viewWillAppear:(BOOL)animated
      {
        [MyTableView reloadData];
      }
      

      请在我们的例子中将 TableView 的 IBOutlet 连接到 XIB 文件中的 MyTableView 到 TableView。

      【讨论】:

        猜你喜欢
        • 2013-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多