私はiOS devを使い慣れていません。インスタンス変数がUITableViewControllerでどのように解放されるのですか?
私はUITableViewControllerのviewDidLoadメソッドでデータを配列にロードしています。ここでのNSLogでコード
- (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;
}
は、データがアクセス可能である呼び出しです。
しかし、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のオブジェクトを別のポインタに割り当てて、セッターを使って割り当てたオブジェクトを取り除いているようです。 'tableCell'とは何ですか? –