我是手机编程的新手。我在数组中存储了一些数据,我想将该数组数据从一个 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 的
数组分配
您 tapCollection1
和 imageCollection1
是retain
属性。因此它应该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/