2010-12-14 50 views
1

我試圖在簡單的細節更改後保存我的plist。使用DetailView如何獲取DetailViewController.m文件上的選定行值?

這是我需要修復的行。

[plist replaceObjectAtIndex:0 withObject:nameDictionary]; 

我需要用獲取所選行的變量替換0。請記住,我正在使用上面教程中的代碼庫。

像indexPath.row會很好,但我不能得到它的工作。

我的數組不能再在詳細視圖中訪問。

回答

1

一個簡單的方法... 創建DetailsView.lets一個NSInterger對象說mySelectedIndex

RootViewControlle didSelectRowAtIndexPath方法..你可以訪問mySelectedIndex

DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; 

dvController.mySelectedIndex = indexPath.row; 

[self.navigationController pushViewController:dvController animated:YES]; 

內的DetailsView

[plist replaceObjectAtIndex:mySelectedIndex withObject:nameDictionary]; 

Second .. Singleton用於存儲數據並在應用程序的任何位置訪問的單變量。

三.. NSUserDefaults的使用..

+0

只要記住你必須在.H否則用字符串傳遞一個NSInteger你需要做的:INT iSelectedIndex = [mySelectedIndex的intValue];
[plist replaceObjectAtIndex:iSelectedIndex withObject:nameDictionary]; – 2010-12-15 15:04:53