Objective c 访问UITableViewController中的NSMutableArray时崩溃
我是Object-c新手,希望在Xcode 4中使用JSON数据源制作一个基于UITableViewController的应用程序。 我导入了JSON框架,并定义了一个NSMutableArray来填充响应:Objective c 访问UITableViewController中的NSMutableArray时崩溃,objective-c,json,nsmutablearray,uitableview,Objective C,Json,Nsmutablearray,Uitableview,我是Object-c新手,希望在Xcode 4中使用JSON数据源制作一个基于UITableViewController的应用程序。 我导入了JSON框架,并定义了一个NSMutableArray来填充响应: - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; NSString *responseString = [[NSString alloc] initWithD
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
items = [responseString JSONValue];
[self.tableView reloadData];
}
我一切都进行得很顺利,但当我尝试访问
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
功能,它会使我的应用程序崩溃
有什么问题吗?
提前谢谢
更新:
我修改了代码的数组填充部分,它解决了崩溃问题:
NSMutableArray*a=[responseString JSONValue]
for(NSDictionary *it in a) {
[items addObject:it];
}
但我仍然不知道为什么…它看起来像是将JSON值分配给实例变量。 对象是自动释放的(“JSONValue”不包含alloc、init或copy等词),因此它将在不久的将来消失 尝试为对象添加属性: 标题: 实施:
@synthesize items;
...
self.items = [responseString JSONValue];
...
- (void)dealloc {
...
self.items = nil;
[super dealloc];
}
@synthesize items;
...
self.items = [responseString JSONValue];
...
- (void)dealloc {
...
self.items = nil;
[super dealloc];
}