-
-
Save munho/2a8bf9789e13241f9b896f95a3dbd205 to your computer and use it in GitHub Desktop.
Using a custom image for a UITableViewCell's accessoryView a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // *********** 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