我有以下的新手问题:这种发布为什么不起作用?
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSArray *anArray;
anArray = [dictionary objectForKey: [NSString stringWithFormat:@"%d", section]];
//here dictionary is of type NSDictionary, initialized in another place.
AnObject *obj = [[AnObject alloc] init];
obj = [anArray objectAtIndex:0];
[anArray release];
return obj.title;
}
如果我运行它,因为它是我会得到一个错误。 如果我不把[anArray发布]它工作得很好。 我不太明白为什么会发生这种情况?
谢谢。
什么JeremyP说。然而,你也不必要地分配了一个'AnObject'的实例,然后将它泄漏到下一行。 – bbum 2010-05-22 18:17:23