Skip to content

Instantly share code, notes, and snippets.

@munho
Forked from vuraltuna/customimage.m
Created January 3, 2018 02:58
Show Gist options
  • Select an option

  • Save munho/2a8bf9789e13241f9b896f95a3dbd205 to your computer and use it in GitHub Desktop.

Select an option

Save munho/2a8bf9789e13241f9b896f95a3dbd205 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];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment