簡體   English   中英

UINavigationController,在堆棧上具有相同視圖控制器的兩個副本

[英]UINavigationController with two copies of the same view controller on stack

我正在使用UINavigationController將UIViewController推送到堆棧上,然后當用戶在表視圖中選擇一行時,我分配了視圖控制器的新版本並將其推送到堆棧上,效果很好,但是當我開始向后按我用來存儲信息的NSMutableArray按鈕似乎正在保留剛剛從堆棧中彈出的視圖控制器的值。

這是將新內容壓入堆棧的方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 1) {
        if (hasLoadedResponses && [responses count] == 0) {
            return;
        }

        VideoDetailViewController_iPhone *nextView = [[VideoDetailViewController_iPhone alloc] initWithNibName:@"VideoDetailViewController_iPhone" bundle:nil withVideoArray:[responses objectAtIndex:indexPath.row]];
        nextView.navController = navController;
        [navController pushViewController:nextView animated:YES];
        [nextView release];
    }

}

我確定我缺少某種愚蠢的東西,但似乎現在找不到。

假設可變數組是[respons objectAtIndex:indexPath.row],因為它是傳遞給新的推入視圖控制器的唯一值,那么如果要對其進行修改,則必須考慮到是同一對象,因此共享修改。

你可以寫:

. withVideoArray:[NSMutableArray arrayWithArray:[responses objectAtIndex:indexPath.row]];

如我所說,我假設對象是您問題的可變數組。

另一個更聰明的解決方案是將用於存儲可變數組的屬性定義為“副本”而不是“保留”。

暫無
暫無

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

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