我知道這是基本的目標C問題,但我有嚴重的問題。我有一個NSMutable數組,我用我的connectionDidFinishLoading中的值填充。我可以在NSLog中看到值正在被正確賦值。但是,當我試圖在DidSelectRow獲取這些值(如我使用一個表視圖,我收到了BAD_ACESS錯誤)來自nsmutable數組的數據在所有方法中都不可見
這裏是我的代碼:
@implementation MainMap
{
NSMutableArray *condition ;
}
..
- (void)viewDidLoad
{
[super viewDidLoad];
}
...
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
condition= [NSMutableArray array];
..adding objects..
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//app crashes in here
NSLog(@"Condition of pressed item is %@",[condition objectAtIndex:indexPath.row]);
}
如果我放在condition= [NSMutableArray array];
裏面viewDidLoad中我得到一個SIGBART
。
此外,我試圖將聲明放在.h文件中,並將其作爲屬性,然後在.m中綜合它,但仍然沒有。也許我錯過了一些東西,那麼你能解決它嗎?
你在這個項目中使用ARC嗎? – SVGreg
不,我不使用。 – ghostrider
然後NSAutoreleasePool已經銷燬你的數據。我看到你已經有了很好的答案。祝你今天愉快。 – SVGreg