我想从一个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. Swift:从ViewController中的tableView传递数据到另一个ViewController
- 6. 将var从一个类传递到ViewController
- 7. 如何将对象从一个ViewController传递到另一个ViewController
- 8. 从2个Tableviews传递数据到ViewController
- 9. Android Bitmap从其他类中返回null
- 10. Android:返回上一个活动并将其传递给数组
- 11. 将Json值传递给其他ViewController?
- 12. 无法从一个UITableViewController“传递数据”到一个UIViewController
- 13. 如何将参数传递给从其他类调用的ViewController
- 14. 如何从第三个viewController返回到第一个viewcontroller?
- 15. 传递组合框selectedItem从一个到另一个形式构造函数返回null。为什么?
- 16. 从ViewController传递数据到Viewcontroller,现在是TabBarController的一部分
- 17. 将JSON数据从一个控制器传递到其他angularjs
- 18. 如何将变量从一个ajax函数传递到其他
- 19. 传递一个Int从一个ViewController到另一个使用segue
- 20. 从一个函数传递返回参数另一个函数
- 21. getTypeParameters返回一个null TypeVariable数组
- 22. 返回字节或传递一个数组的数组功能
- 23. 尝试从null数组中读取 - 尝试从其他Activity中获取数组返回null
- 24. 将Firebase数据从TableViewCell传递到ViewController
- 25. 从viewcontroller反向传递数据到uitableviewcell
- 26. 从viewcontroller tableview传递数据到另一个视图控制器
- 27. 传递返回参数值一个函数到另一个瓶
- 28. 从UIViewController传递数据到UIView
- 29. 从UITableView传递数据到UIViewController
- 30. 从UIViewController传递数据到UIPopover
添加您尝试代码。 –
[视图控制器之间传递数据]的可能的复制(https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) –