作者peliuya (Unknown)
看板MacDev
標題[問題] tabBarView delegate 傳值
時間Mon Oct 28 17:00:07 2013
如果現在有一個 tabBarViewController
內含了 View A 和 View B
我想在 使用者點選 View B , View A viewDidDisappear 時將值傳給View B
我用StoryBoard , 並在ViewB的StoryBoardID 設定為 ViewB,
之後我先宣告了一個 protocol
在 B.m中進行實作
- (void)passValueMethod:(NSString *)string
{
self.Label.text = string;
}
在A.h 中 property(assign, nonatomic) id<passValue> delegate;
在A.m 中
ViewDidDisappear 時
ViewB *B = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewB"];
A.delegate = B;
[A.delegate passValueMethod:@"John"];
可是並沒有正確取得 ViewB 的指針, 所以Label也沒有改變
請問該怎麼做才是正確的呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.44.30
推 appleway:ViewB *B = ... 錯了。 10/28 21:51
→ appleway:instantiateVC W/ ID 是alloc並且init一個全新的VC 10/28 21:53
→ appleway:應該透過 tabBarViewController 取得你要的viewB 10/28 21:53