爲什麼ClassA NSMutableArray arl count仍然是0?ios方法param指定全局變量
有沒有辦法解決這個問題?
B類
B.h
#import <Foundation/Foundation.h>
#import"A.h"
@interface B :NSObject
-(void) doSomeThing;
B.m
@implementation B
-(void)doSomeThing{
NSMutableArray *Array = [[NSMutableArray alloc] initWithObject:@"1",@"2",@"3",@"4",nil];
A *a = [[A alloc] init];
[a getValue:Array];
}
A類
A.H
#import <UKit/UKit.h>
@class B;
@interface A :UIViewController;
@property (strong,nonatomic) NSMutableArray *arl;
-(void) getValue:(NSMutableArray *)Array;
-(IBAction)button:(id)sender;
@end
A.M
@implementation A
@synthesize arl;
-(void) viewDidLoad {
[super viewDidLoad];
B *b = [[B alloc] init];
[b doSomeThing];
}
-(void) getValue:(NSMutableArray *) Array {
arl = Array;
// arl = [[NSMutableArray alloc]initWithArray:Array];
// [arl addObjectFromArray:Array];
NSLog(@"arl count is :%d",[arl count]); // the log at here is 4
}
-(IBAction) button : (id)sender{
NSLog(@"arl count is :%d",[arl count]);// the log at here is 0
}