2010-06-10 35 views
0

我一直在尋找一個解決這個問題的tabBarcontroller一個視圖...但我沒有得到它....更新從另一個視圖控制器

我有一個應用程序,其中有一個tabbarcontroller將兩個視圖添加到它的viewcontrollers數組中。 。一個是列表視圖,另一個是向列表中添加項目的視圖。除了這個tabbarcontroller,我還有一個編輯viewcontroller,當點擊tabbarcontroller中列表視圖的其中一個項目時,它被推入導航控制器。此編輯視圖控制器用於更新列表視圖中的值。

就是我需要的是更新的tabbarcontroller列表視圖,當我去從編輯視圖控制器回來......請任何一個建議我一個解決方案...

回答

0

我會考慮使用通知。當編輯控制器檢測到編輯操作時,您可以關閉通知,並且應該註冊列表視圖控制器以偵聽該通知。編輯視圖控制器可以傳遞通知中的新列表內容。

查看notification center documentation瞭解更多信息。

例如

// In some .h file somewhere 
#define kListHasBeenEditedNotification @"listHasBeenEditedNotification" 

... 
// Inside your list view controller 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(listUpdated:) 
              name:kListHasBeenEditedNotification 
              object:nil]; 

- (void) listUpdated:(NSNotification *)note { 
    // Deal with the list data (which is in [note.userInfo objectForKey:@"listItems"] 
    ... 
} 



... 
// After an edit has been done (inside your edit view controller) 
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:listItems, @"listItems", nil]; 
[[NSNotificationCenter defaultCenter] postNotificationName:kListHasBeenEditedNotification 
                object:self 
                userInfo:userInfo]; 
相關問題