[英]Pass nsmutablearray from one viewcontroller to another view controller
Here I am adding values to nsmutablearray in the firstviewcontroller. 在这里,我向firstviewcontroller中的nsmutablearray添加值。 When I click UIButton I want pass this array to another view controller.
当我单击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;
When I passing firstnamearray value to appointmentdataarray. 当我将firstnamearray值传递给约会数据数组时。
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
[appointmentViewObject setAppointmentDataArray:firstNameArray];
From the above the appointmentdataarray returning a null value. 从上面的约会数据数组返回空值。
[self presentModalViewController:appointmentViewObject animated:YES];
[appointmentViewObject release];
您是否已分配阵列?
NSMutableArray* firstNameArray = [NSMutableArray array];
You can try one thing: in secondviewcontroller.m
add a following method: 您可以尝试一件事:在
secondviewcontroller.m
添加以下方法:
-(id) initwithnibName:(NSString*)_nib withArray:(NSMutableArray*)_array{
self = [super initWithNibName:_nib bundle:nil];
if (self) {
self.array =_array;
}
return self;
}
and add -(id) initwithnibName:(NSString*)_nib withArray:(NSMutableArray*)_array;
并添加
-(id) initwithnibName:(NSString*)_nib withArray:(NSMutableArray*)_array;
to secondviewcontroller.h
. 到
secondviewcontroller.h
。
Now replace secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil]; [appointmentViewObject setAppointmentDataArray:firstNameArray];
现在替换
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil]; [appointmentViewObject setAppointmentDataArray:firstNameArray];
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil]; [appointmentViewObject setAppointmentDataArray:firstNameArray];
with secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initwithnibName:@"secondviewcontroller" withArray:firstNameArray];
与
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initwithnibName:@"secondviewcontroller" withArray:firstNameArray];
Hope this helps. 希望这可以帮助。
Try modifying statement: 尝试修改语句:
[appointmentViewObject setAppointmentDataArray:firstNameArray];
With this: 有了这个:
[appointmentViewObject setAppointmentDataArray:[NSArray arrayWithArray:firstNameArray]];
use this: 用这个:
secondviewcontroller.h file secondviewcontroller.h文件
NSMutableArray* AppointmentDataArray;
@property(nonatomic,retain) NSMutableArray* AppointmentDataArray;
-(void)setMyArray:(NSMutableArray *)arr;
secondviewcontroller.m file 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;
}
///////When you push ////////当您按下
secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
[appointmentViewObject setMyArray:firstNameArray];
[self presentModalViewController:appointmentViewObject animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.