Guest User

Untitled

a guest
Aug 29th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. Adding images to a cell in table view
  2. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3. {
  4. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  5. if(cell == nil)
  6. {
  7. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  8. reuseIdentifier:cellIdentifier];
  9. }
  10. if(indexPath.row == 0)
  11. {
  12. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  13. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image1.png", ]];
  14. [cell.contentView addSubview:imageView];
  15. [imageView release];
  16.  
  17. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  18. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image2.png", ]];
  19. [cell.contentView addSubview:imageView];
  20. [imageView release];
  21.  
  22. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  23. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image3.png", ]];
  24. [cell.contentView addSubview:imageView];
  25. [imageView release];
  26.  
  27. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  28. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image4.png", ]];
  29. [cell.contentView addSubview:imageView];
  30. [imageView release];
  31. }
  32. else if(indexPath.row == 1)
  33. {
  34. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  35. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image5.png", ]];
  36. [cell.contentView addSubview:imageView];
  37. [imageView release];
  38.  
  39. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  40. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image6.png", ]];
  41. [cell.contentView addSubview:imageView];
  42. [imageView release];
  43.  
  44. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  45. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image7.png", ]];
  46. [cell.contentView addSubview:imageView];
  47. [imageView release];
  48.  
  49. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  50. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image8.png", ]];
  51. [cell.contentView addSubview:imageView];
  52. [imageView release];
  53. }
  54. else if(indexPath.row == 2)
  55. {
  56. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  57. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image9.png", ]];
  58. [cell.contentView addSubview:imageView];
  59. [imageView release];
  60.  
  61. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
  62. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image10.png", ]];
  63. [cell.contentView addSubview:imageView];
  64. [imageView release];
  65. }
  66. else
  67. {
  68. // Do something here
  69. }
  70. return cell;
  71. }
  72.  
  73. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(220.0f, 5.0f, 150.0f, 38.0f)];
  74. [button setImage:[UIImage imageNamed:@"Arrow"] forState:UIControlStateNormal];
  75. [button addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
  76. [cell addSubview:button];
  77. [button release];
  78.  
  79. - (void)doSomething
  80. {
  81. [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES]
  82. }
  83.  
  84. IBOutlet UIImageView *image,*image12;
  85.  
  86. In .m file
  87. cellforrowAtIndexPath
  88. {
  89. UIImage *image1=[UIImage imageNamed:@"name.jpg"];
  90. image=[[UIImageview alloc]initWithImage:image1];
  91. image.frame=CGRectMake(0,0,50,50);
  92.  
  93. [cell addSubview:image];
  94.  
  95. UIImage *image13=[UIImage imageNamed:@"name.jpg"];
  96. image12=[[UIImageview alloc]initWithImage:image13];
  97. image12.frame=CGRectMake(50,0,50,50);
  98.  
  99. [cell addSubview:image12];
Add Comment
Please, Sign In to add comment