iphone - 如何将数组从一个 View 传递到 iphone 中的另一个 View

标签 iphone ios

我是手机编程的新手。我在数组中存储了一些数据,我想将该数组数据从一个 View 传递到另一个 View 。我尝试了什么但它不起作用。任何人都可以告诉我什么是错误的

#import"firstviewcontroller.h"

 @property(nonatomic,retain)NSMutableArray *tapCollection;
 @property(nonatomic,retain)NSMutableArray *imageCollection;

#import"firstviewcontroller.m"

   @synthesize imageCollection,tapCollection;
    -(void)viewdidload
    {
    self.tapCollection = [[NSMutableArray alloc] init];
    self.imageCollection = [[NSMutableArray alloc] init];
    }
    - (void)insertNewObject:(id)sender
    {

        secondviewcontroller*r= [[secondviewcontrolleralloc] initWithNibName:@"secondviewcontroller" bundle:nil];
        self.navigationController.navigationBar.tintColor=[UIColor blackColor];
         r.imageCollection1 =imageCollection;
             r.tapCollection1 =tapCollection;
        [self.navigationController pushViewController:r animated:YES];

    }

实际上我存储在数组中的数据是图像和按钮标签值。这里在控制台中显示我存储在数组中的图像和按钮标签值

2013-03-19 21:54:03.374 Taukyy[290:1c103] (
    0,
    "<UIImage: 0x9cd59e0>",
    1,
    "<UIImage: 0x9cd6220>",
    2,
    "<UIImage: 0x9cd6b70>"
)

导入“secondviewcontroller.h”

@property(nonatomic,retain)NSMutableArray *tapCollection1;
@property(nonatomic,retain)NSMutableArray *imageCollection1;

导入“secondviewcontroller.m”

@synthesize tapCollection1,imageCollection1;
- (void)viewDidLoad
{
    imageCollection1 = [[NSMutableArray alloc] init];
   tapCollection1 = [[NSMutableArray alloc] init];
   NSLog(@"%@",tapCollection1);
   NSLog(@"%@",imageCollection1);
}

但是这里没有显示数值,显示如下

2013-03-19 21:29:16.379 Taukyy[594:1c103] (
)
2013-03-19 21:29:16.380 Taukyy[594:1c103] (
)
2013-03-19 21:29:16.381 Taukyy[594:1c103] (
)

请任何人告诉我这段代码有什么错误 谢谢 阿斯拉姆

最佳答案

secondviewcontroller.m 中删除 viewDidLoad 的 数组分配

tapCollection1imageCollection1retain 属性。因此它应该retain 分配的对象。

你的 secondviewcontroller.h 应该是这样的,

@property(nonatomic,retain)NSMutableArray *tapCollection1;
@property(nonatomic,retain)NSMutableArray *imageCollection1;

- (void)viewDidLoad
{
  //remove the allocation codes
}

你可以在 firstviewcontroller.m 中记录它,比如,

 - (void)insertNewObject:(id)sender
    {

         secondviewcontroller*r= [[secondviewcontrolleralloc] initWithNibName:@"secondviewcontroller" bundle:nil];
         self.navigationController.navigationBar.tintColor=[UIColor blackColor];
         r.imageCollection1 =imageCollection;
         r.tapCollection1 =tapCollection;
         NSLog(@"%@",r.imageCollection1);
         NSLog(@"%@",r.tapCollection1);
        [self.navigationController pushViewController:r animated:YES];

    }

关于iphone - 如何将数组从一个 View 传递到 iphone 中的另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15505041/

相关文章:

iPhone - GestureRecognizer 有时不触发?

iphone - 如何使用 CoreMidi 将 Midi 时间码转换为实际时间

iOS内容管理系统

ios - 如何链接两个相互连接的 Collection View ?

ios - 如何在锁屏 iOS 上设置音轨(艺术作品、专辑等)的元数据?

iphone - 如何从 iPhone 向 Windows 发送消息?

ios - 使用 MKMapView、核心位置和核心数据

ios - xml 解析器委托(delegate)不工作

ios - -[__NSCFDictionary setObject :forKey:]: mutating method sent to immutable object

ios - 切换ios模拟器总是报错