我正在使用.XIB而没有ARC。我将NSMultableArray的值传递给另一个视图,如果我把[self presentModel ...],它可以工作,但是如果我用一个按钮调用AnotherView,那么AnotherView的NSMultableArray的值为null!
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写的是“null”
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; }
答案 0 :(得分:0)
这些不应该是必要的:
self.superAnotherView.arrayOfTheAnotherView = [[NSMutableArray alloc]init];
[self.superAnotherView.arrayOfTheAnotherView retain];
初始化类时已初始化属性。
事实上,你的显式保留线根本不是必需的;你没有尽可能地发布它们,只是将保留计数2放在必须释放两次。
我认为这里有一些东西,方法和视图控制器没有按你想要的顺序调用,可能与标签栏有关。
答案 1 :(得分:0)