我有:
NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:[customArray objectAtIndex:0], [customArray objectAtIndex:1], nil];
我需要otherArray在每次推送后收集arr1数组。所以otherArray将包含一些arr1数组。我怎么能这样做?
答案 0 :(得分:0)
NSMutableArray *otherArray=[NSMutableArray array];
每次推动后:
[otherArray addObject:[NSMutableArray arrayWithArray:arr1]];
答案 1 :(得分:0)
你问的不清楚?下次要清楚。对于你的休息,一个是解决方案之一。
尝试以下的例子
这是我的FirstViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController
{
NSArray *first_Array;
}
-(IBAction)nextViewController:(id)sender;
@end
This is my FirstViewController.m .Call nextViewcontroller method with a button
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
first_Array=[[NSArray alloc] initWithObjects:@"one",@"two",@"three",@"four",@"five",@"six",@"seven",@"eight",@"nine",@"ten", nil];
}
-(IBAction)nextViewController:(id)sender
{
SecondViewController *obj=[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj receivingArrayFromFirstViewController:first_Array];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
This is my SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
}
-(void)receivingArrayFromFirstViewController:(NSArray*)array;
@end
This is my SecondViewController.m
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)receivingArrayFromFirstViewController:(NSArray*)array
{
NSMutableArray *arr=[NSMutableArray arrayWithArray:array];
NSLog(@"The received array %@",arr);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end