0

.XIBを使用しており、ARCは使用していません。NSMultableArrayの値を別のビューに渡します。[selfpresentModel...]を指定すると機能しますが、ボタンを使用して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; }
4

2 に答える 2

0

これらは必要ないはずです:

self.superAnotherView.arrayOfTheAnotherView = [[NSMutableArray alloc]init]; 
[self.superAnotherView.arrayOfTheAnotherView retain];

クラスが初期化されるときに、プロパティはすでに初期化されています。

実際、明示的な保持行はまったく必要ありません。あなたは私が見る限りそれらを解放しておらず、2回解放しなければならないように保持カウントを2にしているだけです。

ここでは、メソッドとビューコントローラが希望どおりに呼び出されていないことが起こっていると思います。おそらく、タブバーと関係があります。

于 2012-08-31T01:59:18.287 に答える
0

発見!私はAPPデリゲートのMVC A配列を使用していますが、その値は失われません。AppDelegate NSMutableArray *arrayDelegate; View.m AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; [appDelegate.arrayDelegatePedido addObject:@"title"]; //例えば

于 2012-09-13T16:04:40.567 に答える