简体   繁体   English

将nsmutablearray从一个ViewController传递到另一个View Controller

[英]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.

相关问题 将NSMutableArray传递给另一个视图控制器-不起作用 - Pass NSMutableArray to another view controller - not working 如何从一个ViewController在另一个View Controller中为NSString设置值 - How to set value for NSString in another view controller from one viewcontroller 从子级Viewcontroller(Tab)传递到视图控制器 - Pass from a child Viewcontroller (Tab) to a view controller 如何以编程方式从一个情节提要中的一个视图控制器转到另一个情节提要中的另一个视图控制器? - How to go from one view controller in One storyboard to another viewcontroller in another storyboard programmatically? 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 如何将对象从一个ViewController传递到另一个ViewController - How do I pass object from one ViewController to another ViewController 如何使用委托将数据从一个视图控制器传递到另一个视图控制器? - how to use delegate to pass data to from one View Controller to another? 将字符串值从一个视图控制器传递给另一个 - Pass a string value from one view controller to another 如何将数组从一个视图 controller 传递到另一个视图? - How to pass an array from one view controller to another? 如何将变量从一个视图控制器传递到另一个? - How to pass a variable from one view controller to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM