2012-02-26 2 views
0

저는 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 
+0

'_data'와'self.data'는 어떻게 선언되어 있습니까? – sch

+2

'_data = [info.news];'은 (는) 잘못된 구문입니다. 그건 오타예요? –

+0

'cell = tableCell; self.tableCell = nil;'네가 ivar에있는 객체를 다른 포인터에 할당 한 다음 setter를 통해 방금 할당 한 객체를 제거하는 것처럼 보입니다. 'tableCell'이란 무엇입니까? –

답변

0

그것은 당신이 게시 한 코드에 의해 단지 말할 어렵지만 viewDidLoad_data 개체를 보관해야합니다. 시도해보십시오.

PANewsListModel *info = [PADataSource getNewsList]; 
_data = [info.news retain]; 

dealloc 방법으로 출시하십시오.

+0

또는 retain 유형 인 경우 setter를 대신 사용할 수 있습니다.'self.data = ??? ' – sch

+0

예, 가능합니다. 그러나 그는 헤더를 게시하지 않았기 때문에 이것이 작동 할 수도 있습니다. – edc1591

+0

나는 당신의 awnser를 tryed했지만 그것이 작동하지 않았다면, 나는 더 많은 정보를 가지고 질문을 업데이트했다. 아마 내 실수가 거기에있다. –

관련 문제