簡體   English   中英

表格視圖中的數據不會從一個視圖更新到另一個視圖

[英]Data does not get updated on the table view from one view to the next

我正在嘗試從一個表視圖控制器移動到另一個。 我正在發送一些數據,並且數據已傳遞,但ID在表視圖中未更新。 也就是說,當我單擊表格視圖中的選項之一時,它再次顯示相同的屏幕。 這是我用來推送表格視圖的代碼片段:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Navigation logic may go here. Create and push another view controller.
    devicedetailTableViewController *detailViewController = [[devicedetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

// NSLog(@"%@",detailViewController.details);
    [self.navigationController pushViewController:detailViewController animated:YES];
    detailViewController.details = self.data[indexPath.row];

}

請幫忙! 請注意:我不在這里使用情節提要,因為前一個屏幕是登錄屏幕,廣告搜索在這里給我造成了問題。 所以我決定只改用代碼。 因此,我不能使用情節提要。

PS:我知道數據正在傳遞,因為我可以在日志中看到它。 這就是我加載數據的方式:

- (UITableViewCell *)tableView:(UITableView *)tableView      cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [self.tableView registerNib:[UINib nibWithNibName:@"nibname"
                                                bundle:nil]
                            forCellReuseIdentifier:@"Cell"];
    //static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (!cell)
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = [self devices];
            cell.detailTextLabel.text = @"Name";
            break;
        case 1: {
            NSString *battlife = [details objectForKey:@"battlife"];

            cell.textLabel.text = battlife;
            cell.detailTextLabel.text = @"Battery Life";
            break;
            }
        case 2:{
            cell.textLabel.text = [details objectForKey:@"location"];
            cell.detailTextLabel.text = @"Location";
            break;}

        default:
            break;
    }

    return cell;
}

您在設置數據之前先推動視圖,

[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.details = self.data[indexPath.row];

先做數據集然后推送

detailViewController.details = self.data[indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];

您可能還需要執行[table reloadData],具體取決於您如何在第二個VC上加載數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM