I was searching this solution for long time, and at last I found it. First of all, declare all the objects in your SecondViewController.h file like
@interface SecondViewController: UIviewController
{
NSMutableArray *myAray;
CustomObject *object;
}
Now in your implementation file, allocate the memory for those objects like this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
myAray=[[NSMutableArray alloc] init];
object=[[CustomObject alloc] init];
}
return self;
}
Now you have allocated the memory for Array
and object. Now you can fill that memory before pushing this ViewController
.
Go to your SecondViewController.h and write two methods:
-(void)setMyArray:(NSArray *)_myArray;
-(void)setMyObject:(CustomObject *)_myObject;
In the implementation file, you can implement the function:
-(void)setMyArray:(NSArray *)_myArray
{
[myArra addObjectsFromArray:_myArray];
}
-(void)setMyObject:(CustomObject *)_myObject
{
[object setCustomObject:_myObject];
}
Expecting that your CustomObject
must have a setter function with it.
Now your basic work is done. Go to the place where you want to push the SecondViewController
and do the following stuff:
SecondViewController *secondView= [[SecondViewController alloc] initWithNibName:@"SecondViewController " bundle:[NSBundle MainBundle]] ;
[secondView setMyArray:ArrayToPass];
[secondView setMyObject:objectToPass];
[self.navigationController pushViewController:secondView animated:YES ];
Take care for spelling mistakes.