'self.data ='는 autorelease NSMutableArray 객체와 NSMutableDictionary 객체가 포함되어 있다고 생각했지만 결국 테이블의 cellForRowAtIndexPath 메소드가 self.data의 NSDictionaries에 액세스하려고하면 EXC_BAD_ACCESS가 발생합니다.유지 된 속성에 자동 회수 객체를 할당하면 보관 횟수가 늘어 납니까?
@property (strong, nonatomic) NSMutableArray *data;
- (void) updateReceivedData:(NSData *) jsonData
{
NSMutableArray *fetchedData = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
self.data = [self convertDates:fetchedData withFormat:kMySQLDateTimeFormat];
[self.tableView reloadData];
}
}
- (NSMutableArray*) convertDates:(NSMutableArray *) array withFormat:(NSString *) format
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:format];
NSMutableArray *newArray = [NSMutableArray arrayWithArray:array];
for (NSMutableDictionary *dict in newArray)
{
for (id key in dict.allKeys)
{
if ([[dict objectForKey:key] isKindOfClass:[NSString class]])
{
NSString *value = [dict objectForKey:key];
NSDate *date = [dateFormatter dateFromString:value];
if (date) [dict setObject:date forKey:key];
}
}
}
[dateFormatter release];
return newArray;
}
여기 NSLogs 사이에 BAD_ACCESS가 throw됩니다.
좀비에- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog (@"Cell was nil");
cell = [[[CustomCell alloc] init] autorelease];
}
NSDictionary *dict = [[NSDictionary alloc] init];
if (_isFiltered){
dict = [self.filteredData objectAtIndex:indexPath.row];
} else {
dict = [self.data objectAtIndex:indexPath.row];
}
NSLog (@"Filling Label 1");
cell.IDLabel.text = [[dict objectForKey:@"Id"] stringValue];
NSLog (@"Filling Label 2");
cell.firstNameLabel.text = [dict objectForKey:@"firstName"];
[dict release];
return cell;
}
예외가 발생하는 예외는 무엇입니까? –
질문에 '-cellForForAtIndexPath'코드를 추가했습니다. – TijuanaKez
속성 선언에서'strong'을 사용한다고 가정하면'self.data = foo'는 객체를 유지합니다. 그러나 다른 곳에서 다른 코드가 너무 많이 공개되는 것을 막을 수는 없습니다. 오브젝트를 한 번 릴리스해야 할 가능성이 높습니다. 실제로 한 번 * 두 번 릴리스합니다. 문제를 찾기보다는 ARC를 사용하는 것이 더 쉽습니다. –