NSArray assignment
I have two viewControllers and one has to pass an array to another, but on receiving side i am always getting count 0. here is what i did
classA.h
Class A : UIViewController
{
@private
NSMutableArray *_array;
}
@property (nonatomic, retain ) NSMutableArray *array;
@end
classA.m
@implementation
@synthesis array =_array;
-(void) nowShow
{
int objCount = [ _array count ]; // This is always coming as 0 though i tried various ways (listed below )
}
@end
classB.m
-(开发者_如何转开发void) method:(id)sender {
NSMutableArray *msgArray = [[NSMutableArray alloc] initWithCapacity:1];
for ( int i = 0 ; i <objCount; i++ ){
unsigned int idMsg = msgId[i];
[msgArray addObject:[NSNumber numberWithUnsignedInt:idMsg]];
}
classA *classAController = [[classA alloc] initWithStyle:UITableViewStylePlain];
//[ classAController.array arrayWithObject
//[classAController.array addObjectsFromArray:msgArray];
[ classAController.array initWithArray:msgArray];
//[classAController.array setArray:moveArray];
[self presentModalViewController:classAController animated:YES];
}
Any suggestion guys
You shouldn't call any init
method unless it's immediately after calling alloc
.
With properties, all you need to use is assignment:
classAController.array = msgArray;
The keyword should be @synthesize not @synthesis
edit: also you want to synthesize the property "array", not the instance variable _array
精彩评论