0

我有问题UItableview,当我viewWillAppear每次查看表时用于检索更新的数据时,这给了我例外。

请任何人帮助我如何刷新表格视图,以便在调用viewWillAppear之前对其进行更新?CellforrowAtindexPath

这是我的代码viewWillAppear

-(void)viewWillAppear:(BOOL)animated
{

     [super viewWillAppear:YES];
     [self.tableView reloadData];//table was filled in viewDidLoad.

}

这里是 CellforrowAtindexPath` :(mainArray 上的异常,这意味着通过 viewWillAppear 更新表格和调用 cell 存在冲突):

//Methods to retrive all selected words , thier sound and picture for the mother
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifer = @"Cell";
    UITableViewCell *cell= [ tableView dequeueReusableCellWithIdentifier:CellIdentifer];

    cell.textLabel.font = [UIFont systemFontOfSize:17.0];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifer];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:17.0];
    UILabel *label ;

    label=(UILabel *)[cell viewWithTag:1];

    NSString *value = [[self.mainArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    label.text = value;
    label.textAlignment=NSTextAlignmentRight;
    label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

    //self.tableView.separatorColor = [UIColor blackColor];TRY TO SEPARETE BETEWEEN LINES OF TABLE
    UIButton *butt =(UIButton *)[cell viewWithTag:2];
    NSString *value2 = [[self.mainArray2 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    butt.restorationIdentifier= value2;
    [butt addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];

    NSString *value3 = [[self.mainArray3 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:value3];
    label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

    return cell;
}
4

1 回答 1

0
  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{

返回self.mainArray.count;}

如果 count 为 0,表格视图将不会调用其他函数。

于 2013-05-16T11:00:36.667 回答