我想從一個UIViewController
傳遞數組到其他viewcontroller。 我嘗試使用屬性(viewcontroller1.array)。 我試過通知(發佈通知和添加觀察者)。 我試過NSUserDefaults
所有的都返回一個空數組。從一個UIViewController傳遞數組到其他ViewController返回null
回答
從陣列是通過
@interface demopreseViewController() {
NSArray* nameArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
nameArr = [NSArray arrayWithObjects: @"Jill Valentine", @"Peter Griffin",nil];
NSLog(@"%@",nameArr);
}
- (IBAction)PresentAction:(id)sender {
ViewController2 *aviewcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"aa"];
aviewcontroller.array1 = nameArr;
[self presentViewController:aviewcontroller animated:YES completion:nil];
}
在的viewController 2其中陣列是
@property (strong, nonatomic) NSArray *array1;
下ViewController2.m
傳遞ViewController2.h下
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"parsed%@",_array1);
}
陣列數據將被傳遞
.I嘗試執行上述類型的步驟已經但仍空數組的IAM獲得。是強制給這樣的「ViewController2 * aviewcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@」aa「];」。 ?當我給上面的行iam得到無法識別的選擇器發送到實例錯誤。當然,我已經給我的故事板指定的名稱標識符。我有許多故事板文件在項目中?如果我給self.storyboard,它會有所作爲嗎? – sampath
您是否嘗試使用故事板的標識符像下面 UIStoryboard *故事板= [UIStoryboard storyboardWithName:@ 「MainStoryboard」 束:無]; –
@sampath,'viewConrtoller2'是視圖控制器類的名稱,所以你需要給你的。 – vaibhav
定義屬性爲您的陣列
@Property(nonatomic, retain) NSArray *arrayName;
其次
ViewControllerClassName *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"StoryboardIdentifier"];
controller.array = arrayName;
- 1. 從UIViewController回到第一個ViewController
- 2. 將NSString從一個ViewController傳遞到其他的VC NSMutableArray
- 3. 從UIViewController傳遞數據到1返回UIViewController
- 4. 從一個ViewController傳遞數組數據到一個TableView
- 5. segue並將數據從viewcontroller傳遞到viewcontroller到另一個viewcontroller
- 6. 對象在iOS中從一個viewController返回到另一個時返回null
- 7. 將數組從一個servlet傳遞到其他
- 8. PopupViewController返回null到ViewController
- 9. 將核心數據屬性從viewController傳遞到另一個viewController
- 10. Swift:從ViewController中的tableView傳遞數據到另一個ViewController
- 11. 從ViewController B傳遞數據到ViewController A
- 12. 將var從一個類傳遞到ViewController
- 13. 傳遞一個UInt32到一個NSData對象返回(null)
- 14. 如何將對象從一個ViewController傳遞到另一個ViewController
- 15. 將NSString從一個viewController傳遞到另一個viewController沒有IBAction
- 16. 從NSObject類傳遞一個值到UIViewController
- 17. 從2個Tableviews傳遞數據到ViewController
- 18. 如何將數組/字典傳遞給其他viewController?
- 19. Android Bitmap從其他類中返回null
- 20. UITextField.Text從其他視圖返回null
- 21. Android:返回上一個活動並將其傳遞給數組
- 22. 將數據傳遞到其他組件
- 23. 將Json值傳遞給其他ViewController?
- 24. 無法從一個UITableViewController「傳遞數據」到一個UIViewController
- 25. UIViewController沒有傳遞給其他視圖
- 26. 如何將參數傳遞給從其他類調用的ViewController
- 27. 如何從其他表單傳遞數據並返回
- 28. 如何從第三個viewController返回到第一個viewcontroller?
- 29. 傳遞組合框selectedItem從一個到另一個形式構造函數返回null。爲什麼?
- 30. 返回的ViewController比ParentViewController其他的ModalViewController
添加您嘗試代碼。 –
[視圖控制器之間傳遞數據]的可能的複製(https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) –