저는 iOS dev을 처음 사용하며 메모리 문제를 파악하는 데 문제가 있습니다.인스턴스 변수가 UITableViewController에서 어떻게 할당 해제 될 수 있습니까?
저는 UITableViewController의 viewDidLoad 메서드에 데이터가있는 배열을로드하고 있습니다. 코드는 다음과 같습니다
- (void)viewDidLoad
{
[super viewDidLoad];
// Get Data
PANewsListModel *info = [PADataSource getNewsList];
_data = [info.news];
NSLog(((PANewsModel *)[_data objectAtIndex:1]).title);
UIImageView *bkgrd = [[UIImageView alloc]initWithImage:[UIImage imageNamed:BACKGROUND_IMAGE]];
self.tableView.backgroundView = bkgrd;
self.tableView.rowHeight = 100;
}
NSLog 호출에서 데이터에 액세스 할 수 있습니다.
그러나 TableCell을 채우는 방법에서는 메모리 예외가 발생합니다. 코드는 다음과 같습니다
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"tableView");
static NSString *CellIdentifier = @"NewsCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"PANewsCellIB" owner:self options:nil];
cell = tableCell;
self.tableCell = nil;
PANewsModel *newsItem = (PANewsModel *) [self.data objectAtIndex:1];
UILabel *title = (UILabel *)[cell viewWithTag:101];
title.text = newsItem.title; // This instruction gives EXC_BAD_ACCESS
}
[cell sizeToFit];
return cell;
}
이러한 메소드간에 인스턴스 변수를 할당 해제 할 수있는 것은 무엇입니까?
UPDATE : 추가 정보를
이 데이터
.h
@property (nonatomic, retain) NSMutableArray *data;
.m
@synthesize data = _data;
의 선언과 PANewsModel 클래스입니다
@interface PANewsModel : NSObject
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *shortDescription;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) UIImage *photo;
-(id) initWithTitle: (NSString *) t
shortDesc: (NSString *) s
description: (NSString *) d
date: (NSString *) date
image: (UIImage *)image;
@end
'_data'와'self.data'는 어떻게 선언되어 있습니까? – sch
'_data = [info.news];'은 (는) 잘못된 구문입니다. 그건 오타예요? –
'cell = tableCell; self.tableCell = nil;'네가 ivar에있는 객체를 다른 포인터에 할당 한 다음 setter를 통해 방금 할당 한 객체를 제거하는 것처럼 보입니다. 'tableCell'이란 무엇입니까? –