-1

我有:

NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:[customArray objectAtIndex:0], [customArray objectAtIndex:1], nil];  

我需要 otherArray 在每次推送后收集 arr1 数组。所以 otherArray 将包含一些 arr1 数组。我该怎么做?

4

2 回答 2

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
于 2012-11-15T14:16:33.570 回答
0
NSMutableArray *otherArray=[NSMutableArray array];

每次推送后:

[otherArray addObject:[NSMutableArray arrayWithArray:arr1]];
于 2012-11-15T13:43:54.157 回答