Skip to content

Instantly share code, notes, and snippets.

@vuraltuna
Last active February 5, 2020 21:02
Show Gist options
  • Select an option

  • Save vuraltuna/8114515 to your computer and use it in GitHub Desktop.

Select an option

Save vuraltuna/8114515 to your computer and use it in GitHub Desktop.
Using a custom image for a UITableViewCell's accessoryView a
// *********** Using a custom image for a UITableViewCell's accessoryView and having it respond to UITableViewDelegate
UIImage *image = [UIImage imageNamed:@"MenuSectionHeaderArrow.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame; // match the button's size with the image size
[button setBackgroundImage:image forState:UIControlStateNormal];
// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
cell.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
//***********************************************
#pragma mark - checkButtonTapped
- (void)checkButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.foodTableView];
NSIndexPath *indexPath = [self.foodTableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
[self tableView: self.foodTableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
#pragma mark - accessoryButtonTappedForRowWithIndexPath
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
FoodInfoViewController *foodViewController = [[FoodInfoViewController alloc] initWithNibName:@"FoodInfoViewController" bundle:nil];
[foodViewController setBaslik:[infoweb_adi objectAtIndex:indexPath.row]];
[foodViewController setWebStr:[infoweb_cont objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:foodViewController animated:YES];
}
@tohiks

tohiks commented Nov 16, 2015

Copy link
Copy Markdown

nice!

@jim3ex

jim3ex commented Feb 5, 2020

Copy link
Copy Markdown

Thanks, nice solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment