开发者

Multiple Images in a TableView

开发者 https://www.devze.com 2023-01-28 13:48 出处:网络
I have got a tableView with 176 items in a NSMutableArray and I implemented this code for multiple images in my tableView:

I have got a tableView with 176 items in a NSMutableArray and I implemented this code for multiple images in my tableView:

switch (indexPath.row) {
 case 0:
 cell.imageView.image = [UIImage imageNamed:@"meeting_color.png"];
 break;
 case 1:
 cell.imageView.image = [UIImage imageNamed:@"call_color.png"];
 break;
 case 2:
 cell.imageView.image = [UIImage imageNamed:@"calendar_开发者_StackOverflow社区color.png"];
 break;
 case 3:
 cell.imageView.image = [UIImage imageNamed:@"call_color.png"];
 break;
 case 4;
 cell.imageView.image = [UIImage imageNamed:@"calendar_color.png"];
 break;
 default:
 break;
 }

The problem is that I need 176 of these cases and when I run it, it goes extremely slow! Although I implemented the fast scrolling api used in Tweetie.


Can you store the images/strings in an array and just use the indexPath.row to retrieve them as and when needed? Ie. cell.imageView.image = [images objectAtIndex:indexPath.row];

This way you dont need the switch statement?


You can do something like this:

Note: This is just a psuedocode.

String[] img={"calendar_color.png", "call_color.png", "meeting_color.png"};
for (int i=0; i <176; i++)
 {
  if(i==0)
    cell.imageView.image= img[2];
  else if(i % 2==0){
    cell.imageView.image=img[0];
  }
  else {
    cell.imageView.image=img[1];
    }
}

Using this as an insight-> you can fetch all in an Array and fetch the pointers using indexPath.row.

0

精彩评论

暂无评论...
验证码 换一张
取 消