我正在使用.XIB並且沒有ARC。我將NSMultableArray的值傳遞給另一個視圖,如果我把[self presentModel ...],它可以工作,但如果我用一個按鈕調用AnotherView的AnotherView的NSMultableArray的值爲null!iOS將NSMutableArray的值傳遞(保留)到另一個視圖中的另一個NSMutableArray
AnotherView.h
@interface AnotherViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>{
NSMutableArray *otherAnother;
NSMutableArray *arrayOfTheAnotherView;
}
@property (retain, nonatomic) IBOutlet UITableView *tableView;
@property (retain, nonatomic) NSMutableArray *arrayOfTheAnotherView;
AnotherView.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
otherAnother = [[NSMutableArray alloc]init];
otherAnother = [[NSMutableArray alloc]initWithArray:self.arrayOfTheAnotherView];
// [otherAnother addObjectsFromArray:arrayOfTheAnotherView];
NSLog(@"%@", self.arrayOfTheAnotherView);
}
的NSLog的寫 「空」
CurrentView.h
@interface CurrentViewController : UIViewController {
NSMutableArray * arrayCurrentView;
AnotherViewController *superAnotherView;
}
@property (retain, nonatomic) AnotherViewController *superAnotherView;
CurrentView.m
@synthesize superAnotherView;
NSString *x = [[NSString alloc]initWithFormat:@"%@",[label text]];
arrayCurrentView = [[NSMutableArray alloc]init];
[arrayCurrentView retain];
[arrayCurrentView addObject:x];
self.superAnotherView = [[AnotherViewController alloc]initWithNibName:nil bundle:nil];
self.superAnotherView.arrayOfTheAnotherView = [[NSMutableArray alloc]init];
[self.superAnotherView.arrayOfTheAnotherView retain];
[self.superAnotherView.arrayOfTheAnotherView addObjectsFromArray:arrayCurrentView];
我不知道如何保留NSMultableArray的價值,感謝幫助。
這就是我所說的AnotherView:
UIButton *buttonAnother = [UIButton buttonWithType:UIButtonTypeCustom]; [buttonAnother setTag:5]; [buttonAnother addTarget:self action:@selector(switchTabBar:) forControlEvents:UIControlEventTouchDown];
[tabBarViewController.view addSubview:buttonAnother];
- (IBAction)switchTabBar:(id)sender { switch ([(UIButton *)sender tag]) { case 5: [self.tabBarController setSelectedIndex:0]; break; }
嘗試數據存儲:http://stackoverflow.com/questions/5448476/objective-c-singleton-objects-and-global-variables或http://www.galloway.me.uk/教程/單類/ – kezi