Iphone 将阵列添加到NSMUTABLEARRY afrer viewcontroller
我有: 我需要其他阵列在每次推送后收集arr1阵列。因此otherArray将包含几个arr1数组。我怎么能做到Iphone 将阵列添加到NSMUTABLEARRY afrer viewcontroller,iphone,ios,xcode,nsarray,Iphone,Ios,Xcode,Nsarray,我有: 我需要其他阵列在每次推送后收集arr1阵列。因此otherArray将包含几个arr1数组。我怎么能做到 NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:[customArray objectAtIndex:0], [customArray objectAtIndex:1], nil]; 每次推送后: NSMutableArray *otherArray=[NSMutableArray array]; 你问什么不清楚
NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:[customArray objectAtIndex:0], [customArray objectAtIndex:1], nil];
每次推送后:
NSMutableArray *otherArray=[NSMutableArray array];
你问什么不清楚?下次再说清楚。对你来说,放松是解决办法之一 试一下休闲的例子 这是我的第一个ViewController.h
[otherArray addObject:[NSMutableArray arrayWithArray:arr1]];
#导入
#导入“SecondViewController.h”
@界面FirstViewController:UIViewController
{
NSArray*第一个_阵列;
}
-(iAction)下一个可视控制器:(id)发送方;
@结束
这是我的FirstViewController.m。使用按钮调用nextViewcontroller方法
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
first_Array=[[NSArray alloc]initWithObjects:@“一”,“二”,“三”,“四”,“五”,“六”,“七”,“八”,“九”,“十”,零];
}
-(iAction)下一个可视控制器:(id)发送方
{
SecondViewController*obj=[[SecondViewController alloc]initWithNibName:@“SecondViewController”捆绑包:nil];
[self.navigationController pushViewController:obj动画:是];
[obj接收来自FirstViewController的阵列:第一个数组];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束
这是我的第二个视图控制器
#进口
@界面SecondViewController:UIViewController
{
}
-(void)从FirstViewController接收阵列:(NSArray*)数组;
@结束
这是我的第二个ViewController.m
#导入“SecondViewController.h”
@接口SecondViewController()
@结束
@第二视图控制器的实现
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//从nib加载视图后,执行任何其他设置。
}
-(void)从FirstViewController接收阵列:(NSArray*)阵列
{
NSMUTABLEARRY*arr=[NSMUTABLEARRY arrayWithArray:array];
NSLog(@“接收到的阵列%@”,arr);
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束
#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