我有一個要求,我必須將一個字符串值從一個viewController傳遞到另一個按鈕單擊。我也需要使用tabBarController從當前viewController切換到secondViewController。我想:iOS - 將數據從一個viewController傳遞到另一個在xib中使用tabBarController的數據
FirstViewController.h
#進口 「SecondViewController.h」
@property(nonatomic, strong) SecondViewController *secondController;
FirstViewController.m
-(IBAction)go:(id)sender
{
[email protected]"Demo Text";
self.tabBarController.selectedIndex=1; //say secondViewController index is 1
}
SecondViewController.h
#import "FirstViewController.h"
@property(nonatomic, strong) NSString *itemText;
SecondViewController.m
-(void) viewWillAppear (BOOL) animated
{
NSLog(@"Comes from FirstViewController: %@",self.itemText);
}
雖然切換的viewController,但它打印空白。代碼有什麼問題?
應用的破碎工作的罰款。獲取錯誤: ' - [UINavigationController setitemText:]:無法識別的選擇器發送到實例' – Poles 2015-04-01 06:08:07
我放下了我的代碼的第一個(和錯誤的)行,現在一切都應該是正確的。如果你在你的「go」行中設置了一個Xcode斷點,你期望的視圖控制器是「secondVC」嗎? – 2015-04-01 17:42:20