这里我在firstviewcontroller中向nsmutablearray添加值。当我单击UIButton时,我想将此数组传递给另一个视图控制器。
AppointmentClass *appObj = [[AppointmentClass alloc]init];
appObj.subject = [key objectForKey:@"Subject"];
appObj.location = [key objectForKey:@"Location"];
appObj.scheduledStart = [key objectForKey:@"ScheduledStart"];
appObj.scheduledEnd = [key objectForKey:@"ScheduledEnd"];
[firstNameArray addObject:appObj];
[appObj release];
appObj=nil;
当我将firstnamearray值传递给appointmentdataarray时。
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
[appointmentViewObject setAppointmentDataArray:firstNameArray];
从上面看,appointmentdataarray返回一个空值。
[self presentModalViewController:appointmentViewObject animated:YES];
[appointmentViewObject release];
答案 0 :(得分:0)
你分配了阵列吗?
NSMutableArray* firstNameArray = [NSMutableArray array];
答案 1 :(得分:0)
你可以尝试一件事:
在secondviewcontroller.m
中添加以下方法:
-(id) initwithnibName:(NSString*)_nib withArray:(NSMutableArray*)_array{
self = [super initWithNibName:_nib bundle:nil];
if (self) {
self.array =_array;
}
return self;
}
并将-(id) initwithnibName:(NSString*)_nib withArray:(NSMutableArray*)_array;
添加到secondviewcontroller.h
。
现在替换secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
[appointmentViewObject setAppointmentDataArray:firstNameArray];
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initwithnibName:@"secondviewcontroller" withArray:firstNameArray];
希望这有帮助。
答案 2 :(得分:0)
尝试修改声明:
[appointmentViewObject setAppointmentDataArray:firstNameArray];
有了这个:
[appointmentViewObject setAppointmentDataArray:[NSArray arrayWithArray:firstNameArray]];
答案 3 :(得分:0)
使用它:
secondviewcontroller.h文件
NSMutableArray* AppointmentDataArray;
@property(nonatomic,retain) NSMutableArray* AppointmentDataArray;
-(void)setMyArray:(NSMutableArray *)arr;
secondviewcontroller.m文件
@synthesize AppointmentDataArray;
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil
bundle:nibBundleOrNil])) {
// Custom initialization.
AppointmentDataArray = [[NSMutableArray alloc] init];
}
return self;
}
-(void)setMyArray:(NSMutableArray *)arr{
AppointmentDataArray=arr;
}
///////推送时
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
[appointmentViewObject setMyArray:firstNameArray];
[self presentModalViewController:appointmentViewObject animated:YES];