我試圖初始化數組:如何在ARC中初始化NSArray?
在.h文件中
@property (nonatomic, retain) NSArray *accounts;
在.m文件:
@synthesize accounts;
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *arrList = [acAccountStore accountsWithAccountType:accountType];
// This returns array
self.accounts = [NSArray arrayWithArray:arrList]; // I tried debug after
// this and it gives me data in debugger.
// Note array List have 3 data in it.
}
,立即請點擊我調用一個方法:
- (IBAction) ButtonClicked :(id) sender {
NSLog(@" data : %@",[self.accounts objectAtIndex:0]); // Breaks at this point.
// When i tried with debug it gives me (no Objective-C description available)
}
數組的初始化是否正確或者如果代碼不正確請讓我知道了。
主要關注的是當我在viewDidLoad中進行調試時,self.accounts顯示出適當的值。但是在執行完click事件之後,它會爲空並拋出EXEC_BAD_ACCESS錯誤。
感謝您的幫助提前
我沒有得到你。你能再解釋一遍嗎? – insomiac
讓我看看arrList的初始化 – CodaFi