我有以下的新手問題:這種發佈爲什麼不起作用?
- (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