2016-04-14 4 views
0

テーブルビューに異なる画像を表示したい。私はsqliteにイメージ名を格納しました。だから、データベースからイメージ名を尋ねるだけでよいと思うたびに、sqliteのUITableView画像

cell.imageView.image = [UIImage imageNamed:[@"%@.jpg",[self.arraySonglistInfo objectAtIndex:indexPath.row] objectAtIndex:picture]] 

がありますが、何か問題があります。私はここで何をすべきですか? 方法は次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

// Configure the cell... 

NSInteger picture = [self.database.arrayColumnNames indexOfObject:@"picture"]; 

cell.imageView.image = [UIImage imageNamed:[@"%@.jpg",[self.arraySonglistInfo objectAtIndex:indexPath.row] objectAtIndex:picture]]; 

return cell; 
} 

エラーが

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]' 

され、警告 "未使用の式の結果は" この行にあります:

cell.imageView.image = [UIImage imageNamed:[@"%@.jpg",[self.arraySonglistInfo objectAtIndex:indexPath.row] objectAtIndex:picture]]; 
+0

さらに進んでいく必要があります。どのようなエラーがありましたか?何が悪かったのか?どのような方法の中で、そのコード行を入れましたか? –

+0

更新しました、ありがとうございます! – Xie

答えて

0

問題がNSIntegerの絵でありますライン。この計算では、0〜2の数値が必要なときに9223372036854775807という数値が得られました。

+0

もう少し説明してください、私はまた、この行を使用して、名前などのデータベースから他のデータを取得します。 – Xie

+0

その行にブレークポイントを置き、ピクチャの値を確認します。 9223372036854775807は、indexOfObjectのNSNotFound:@ "picture"を意味します。 –

+0

"画像"の名前を変更しましたが、エラーは[__NSArrayM objectAtIndex:]になります:境界3を超えたインデックス3 [0122] – Xie

関連する問題