0

在这里,我将值添加到 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 值传递给约会数据数组时。

secondviewcontroller *appointmentViewObject = [[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil];
[appointmentViewObject setAppointmentDataArray:firstNameArray];

从上面的约会数据数组返回一个空值。

[self presentModalViewController:appointmentViewObject animated:YES];
[appointmentViewObject release];
4

4 回答 4

0

尝试修改语句:

  [appointmentViewObject setAppointmentDataArray:firstNameArray];

有了这个:

  [appointmentViewObject setAppointmentDataArray:[NSArray arrayWithArray:firstNameArray]];
于 2013-05-15T10:18:59.713 回答
0

你分配数组了吗?

NSMutableArray* firstNameArray = [NSMutableArray array];
于 2013-05-15T10:09:09.600 回答
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];

希望这可以帮助。

于 2013-05-15T10:15:12.437 回答
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];
于 2013-05-15T10:23:10.160 回答