2013-10-17 31 views
0

我是iOS編程的新手,目前正在學校上iOS課程。對於我正在做的項目,我們必須爲iPhone編寫基本的主 - 細節應用程序。對於我的應用程序,我創建了一個簡單的待辦事項列表類型的應用程序。每個任務的名稱顯示在主視圖中,任務的名稱可以在詳細視圖中更改。我設置了一個保存按鈕,當按下時有一個展開順序委託。當我按下按鈕時,我會繼續回到主視圖,我無法實時獲取相應單元格的值。我知道它的主視圖正在獲取已更改的信息,因爲更改後的信息在控制權轉移回主視圖並保存後纔會保存。當我重新運行應用程序時,將顯示新名稱而不是默認名稱。iPhone主細節應用程序如何使用細節視圖來更改顯示在主視圖中相應單元格中的文本值

這裏是開卷SEGUE

- (IBAction) done:(UIStoryboardSegue *)segue 
{ 
// index for the cell in the master view table that was changed 
NSIndexPath *changeIndex = [self.tableView indexPathForSelectedRow]; 

[self tableView:self.tableView cellForRowAtIndexPath:changeIndex]; 

// place the new dictionary entry created by the detail view in the location of the 
// array where the old entry was located 
_taskList[changeIndex.row] = self.ChangedEntry; 

// store the change in the plist file 
[_taskList writeToFile:self->documentPlistPath atomically:YES]; 
} 

調用該函數,這似乎改變文本在表格單元格中的代表,但我不知道

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
cell.textLabel.text = _taskList[indexPath.row][TASK_DATA_NAME]; 
return cell; 
} 

所以是的,我只是想弄清楚如何使主視圖反映在詳細視圖中所做的更改,而無需關閉應用程序並重新打開它。哦,我正在使用Xcode 5並定位到iOS 7.

回答

1

基本上,在更新數據模型(_taskList)後,您需要通過調用reloadData來刷新表視圖。這告訴它更新所有的行。

+0

嘿,非常感謝你。那是我需要爲我的項目弄清楚的最後一件事情之一。謝謝。 – user1222073

相關問題