まだまだ学習している最中でしていろいろ検索していたところこちらにたどり着いた次第でございます。
tableViewで実現したい物がうまくいかず悩んでおります、どうかお力添えをお願い申し上げます。
とあるテキストファイルから1行ずつ読み込み、tableViewに表示させようとしております。
テキストファイルを読み込み、tableViewに表示させることは成功しましたが
スクロールをさせるとアプリがクラッシュしてしまいます。
テキストの内容は
111
222
333
444
.
.
と大体300行ぐらい有ります。行数を減らしても変わりませんでした。
cellForRowAtIndexPathのスクロール処理の部分に問題があるとは思うのですがどのように解決したら良いか
教えていただきたいです。
以下ソースです。
-(void)viewDidLoad
{
NSString *paths = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"txt"];
NSString *lotData = [[NSString alloc] initWithContentsOfFile:paths];
NSArray *array = [lotData componentsSeparatedByString:@"\n"];
NSLog(@"%@",array);
self.listData = array;
[array release];
[super viewDidLoad];
}
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellData = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellData];
if (cell == nil){
cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellData] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}