Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. static NSString *CellIdentifier = @"Cell";
  4.  
  5. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  6. if (cell == nil) {
  7. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
  8. }
  9. [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  10.  
  11. UIView * contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
  12.  
  13. UIImageView * cellImg = [[UIImageView alloc]initWithFrame:CGRectMake(5,8,259, 60)];
  14. [cellImg setImage:[UIImage imageNamed:[menuArr objectAtIndex:indexPath.row]]];
  15. [contentView addSubview:cellImg];
  16.  
  17. [contentView setBackgroundColor:[UIColor clearColor]];
  18. [cell.contentView addSubview:contentView];
  19. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  20. return cell;
  21. }
  22.  
  23. #pragma mark - Table view delegate
  24.  
  25. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  26. delegate.sideBarSelectedIndex = indexPath.row;
  27. NSLog(@"delegate.sideBarSelectedIndex: %d",delegate.sideBarSelectedIndex);
  28.  
  29. [UIView commitAnimations];
  30. if (self.sidebarDelegate) {
  31. NSObject *object = [NSString stringWithFormat:@"ViewController%d", indexPath.row];
  32. [self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
  33. [delegate.firstLensePageObj timerFunction:indexPath.row];
  34. }
  35.  
  36. }
  37.  
  38. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  39. cell.imageView.image = [UIImage imageNamed:@"yourImage"];
  40.  
  41. UIImageView *selectedImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Your Image"]];
  42.  
  43. cell.selectedBackgroundView = selectedImageView;
  44.  
  45. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  46. {
  47. static NSString *CellIdentifier = @"Cell";
  48.  
  49. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  50. if (cell == nil) {
  51. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
  52. }
  53. [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  54.  
  55. UIView * contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
  56.  
  57. UIImageView * cellImg = [[UIImageView alloc]initWithFrame:CGRectMake(5,8,259, 60)];
  58. if (delegate.sideBarSelectedIndex == indexpath.row){
  59. //Selected cell
  60. [cellImg setImage:[UIImage imageNamed:[selectedMenuArr objectAtIndex:indexPath.row]]];
  61. }else {
  62. //Unselected cell
  63. [cellImg setImage:[UIImage imageNamed:[menuArr objectAtIndex:indexPath.row]]];
  64. }
  65. [contentView addSubview:cellImg];
  66.  
  67. [contentView setBackgroundColor:[UIColor clearColor]];
  68. [cell.contentView addSubview:contentView];
  69. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  70. return cell;
  71. }
  72.  
  73. #pragma mark - Table view delegate
  74.  
  75. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  76. delegate.sideBarSelectedIndex = indexPath.row;
  77. NSLog(@"delegate.sideBarSelectedIndex: %d",delegate.sideBarSelectedIndex);
  78.  
  79. [UIView commitAnimations];
  80. if (self.sidebarDelegate) {
  81. NSObject *object = [NSString stringWithFormat:@"ViewController%d", indexPath.row];
  82. [self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
  83. [delegate.firstLensePageObj timerFunction:indexPath.row];
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement