【问题标题】:NSMutable Array from One Class to Another Class in iPhoneiPhone中从一个类到另一个类的NSMutable数组
【发布时间】:2012-05-01 19:17:17
【问题描述】:

我在 FirstViewController 类中有一个 NSMutable 数组,我想将该数组传递给 SecondViewController 类。我想在 SecondViewController 类中使用它。我在 Xcode 4.2.1 中使用 ARC 执行此操作...我怎么能...?以及在设置属性时我想使用哪些属性...(或)解释我也使用 Appdelegate 文件...

【问题讨论】:

    标签: iphone objective-c ios5 nsmutablearray xcode4.2


    【解决方案1】:

    有两种方法可以做到这一点。

    1:在appdelegate中为NSMutableArray创建一个属性,在FirstViewController中设置数组的值,在SecondViewController中获取值。

    2:在SecondViewController中为NSMutableArray创建一个属性,并为FirstViewController调用该属性但创建SecondViewController的对象,并通过FirstViewController中secondViewController的对象引用调用该属性。

    【讨论】:

    • 谢谢...请您在 Xcode 4.2.1 中以编程方式解释...我已经尝试使用您解释的方式...
    • 当然,您尝试了 1 还是 2 方法?
    • 我尝试了很多方法...我尝试使用以数组作为参数的方法发送消息。在这里我可以访问数组但是数组的范围在 SecondViewController 中的特定方法中.. 无法通过课程访问...
    • 在 SecondViewController 头文件中,声明 @property(nonatomic,retain) NSMutableArray *MyArray;然后从 FirstViewController 执行此操作 SecondViewController *NextViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; NextViewController.MyArray = thisClassarray;
    【解决方案2】:

    在当前班级

    #import "SecondViewController"
    

     SecondViewController *NextViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    
            NextViewController.nextClasssArray = thisClassarray;
    

    二等.h

    @property(nonatomic,retain) NSMutableArray *nextClasssArray;
    

    二等.m

    @synthesize nextClasssArray;
    

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 2017-10-19
      相关资源
      最近更新 更多