如何爲我的表格視圖的每個單元格設置不同的圖像。我想這樣做,通過圖像名稱如何爲我的表格視圖的每個單元格設置不同的圖像
2
A
回答
6
使用下面的代碼的陣列...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/* Initialise the cell */
static NSString *CellIdentifier = @"MyTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
/* Configure the cell */
NSString *cellImageName = [[self cellImageNames] objectAtIndex:[indexPath row]];//cellImageNames ism image names array where
UIImage *cellImage = [UIImage cellImageName];
[[cell imageView] setImage:cellIcon];
// Other cell configuration code...
return cell;
}
希望,這將幫助你......
5
例如:
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%i.png", indexPath.row]];
或
cell.imageView.image = (UIImage *)[yourArray objectAtIndex:indexPath.row];
+0
thanx幫助朋友 – Toseef 2012-05-01 08:36:31
5
您的搜索解決方案n爲這裏去這個鏈接How to add UIImage in the UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"TableView";
MainView *cell = (MainView *)[tableView dequeueReusableCellWithIdentifier: MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil];
cell = tableCell;
}
[cell LabelText:[arryList objectAtIndex:indexPath.row]];
[cell ProductImage:[imagesList objectAtIndex:indexPath.row]];
return cell;
}
的UITableView與圖像顯示像
-1
cell.imageView.image = [UIImage imageNamed:@"image.png"];
相關問題
- 1. 如何設置不同圖像的每個單元格的圖像視圖iOS.Xamarin
- 2. 如何在表格視圖單元格上設置突出顯示的圖像?
- 3. 如何在每個表格視圖單元格中加載不同的數據
- 4. 在表視圖單元格內的UIImageView中設置圖像
- 5. 如何在表格視圖單元格背景中設置圖像動畫
- 6. 如何設置表格視圖單元格的位置,因爲選項卡欄阻止單元格?
- 7. 如何爲同一個表中的不同單元格設置不同的UITableViewCellStyle?
- 8. 當單元格插入表格時,自定義表格視圖單元格內的圖像視圖消失
- 9. 如何爲不同的單元格設置不同的顏色
- 10. 如何在同一個表格視圖單元格的左側顯示錶格視圖標題的標籤?
- 11. 如何在圖像中像這樣添加表格視圖中的單元格?
- 12. 給圖像不同的單元格tableview
- 13. 如何在表格視圖行中放置多個單元格?
- 14. 如何設置最後一個單元格的背景圖像並在iPhone中查找表格視圖高度?
- 15. 帶圖像的表格視圖單元格
- 16. 在表格視圖中獲取單元格上方的圖像
- 17. 自定義表格視圖的單元格圖像扭曲
- 18. 圖像查看錶格視圖中的單元格
- 19. 調整表格單元格中的圖像視圖iphone
- 20. 靜態表格單元格左側的圖像或視圖
- 21. 如何展開我的表格視圖單元格?
- 22. 不同控件的表格視圖單元格
- 23. 'segue'從不同的表格視圖單元到同一個視圖控制器
- 24. 在單個分組表格視圖中添加兩個不同的單元格
- 25. 如何使每個單元格的列表視圖像卡或盒子?
- 26. 如何設置點擊以展開iOS中的表格視圖單元格?
- 27. 如何讓我的表格視圖看起來更像iOS設置應用中的表格視圖?
- 28. 如何爲每個引腳設置不同的圖像? Xamarin iOS
- 29. 當滾動表格視圖單元格的視圖,單元格文本更改
- 30. 我可以爲每個視圖設置不同的tintColor嗎?
請仔細閱讀[常見問題](http://stackoverflow.com/faq)第一。 – 2012-04-28 10:31:29