在两个UIViewController之间传递NSMutableArray [英] Pass NSMutableArray between two UIViewController's

查看:43
本文介绍了在两个UIViewController之间传递NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图控制器,名称分别为RootViewController和SecondViewController.在FirstViewController中,我有这个NSMutableArray

I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have this NSMutableArray

@interface RootViewController : UITableViewController {

NSMutableArray *allClasses;}@property (nonatomic,retain) NSMutableArray *allClasses;

在RootViewController中,我用allClasses中的所有对象填充UITableView

In the RootViewController I populate the UITableView with all the objects within allClasses

在我的SecondViewController中,

In my SecondViewController I have

@interface SecondViewController : UIViewController <UITextFieldDelegate,UIPickerViewDelegate> {

NSMutableArray *arrayStrings;}

我有一个将新的NSString添加到arrayStrings的方法.我的目标是能够通过尝试类似于allClasses = arrayStrings的方法将arrayStrings传递给RootViewController.这样,在加载RootViewController时,它可以填充新信息.

I have a method that adds new NSStrings to the arrayStrings. My goal is to be able to pass the arrayStrings to the RootViewController by trying something similar to allClasses = arrayStrings. That way when the RootViewController is loaded it can populate with new information.

我将如何完成这项任务?

How would I got about accomplishing that task?

推荐答案

-(void)viewWillAppear:(BOOL)animated

此委托方法.在此方法内

this delegate method. Inside this method

self.allClasses = SecondViewControllerObj.arrayStrings;

SecondViewControllerObj是在RootViewController中声明为成员的SecondViewController的对象,并用于导航到该视图

SecondViewControllerObj is the object of SecondViewController declared in RootViewController as a member and which is used to navigate to that view

喜欢

if(SecondViewControllerObj == nil)
    {
        SecondViewControllerObj = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    }

        [self.navigationController pushViewController:SecondViewControllerObj animated:YES];

这篇关于在两个UIViewController之间传递NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆