Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7498543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:30:37+00:00 2026-05-29T19:30:37+00:00

I’m trying to figure this out for some time now. I am creating a

  • 0

I’m trying to figure this out for some time now. I am creating a UIButton programmatically within a tableview cell. Upon clicking the button I want to segue or push to another view controller. This is a piece of cake if I use StoryBoard, create the button there, and then control-drag a segue to the destination VC. I however do not want to do it this way for various reasons. Below is my code thus far.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath



// <<<< bunch of code snipped out here to keep this example short >>>



for(UIButton *button in cell.subviews)
{
    [button removeFromSuperview];
}
UIImage *image = [UIImage imageNamed:[contentArray_ objectAtIndex:indexPath.row]];
UIButton *imageButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 240, 240)];
[imageButton setImage:image forState:UIControlStateNormal];
imageButton.layer.masksToBounds = YES;
imageButton.layer.cornerRadius = 5.0;
imageButton.layer.borderWidth = 1.0;
imageButton.layer.borderColor = [[UIColor grayColor] CGColor];

CGAffineTransform rotateButton = CGAffineTransformMakeRotation(M_PI_2);
imageButton.transform = rotateButton;

cell.backgroundColor = [UIColor clearColor];
[cell addSubview:imageButton];

return cell;

Now, for each row in this table a button with an image will be created programmatically. I also rotate the button – yes this is a horizontal table view.

So how do I take action on button clicks? All buttons would go to the same destination view controller…

PS – I’m using Xcode 4.2 with ARC (not sure that really matters).


—– Update to Question

I’ve implemented the code suggestion (Thanks jrturton) however I believe that because I’m in a UITableView cell I cannot present a modal view controller. I now have the following code…

.h file:

@interface DetailsHorizontalPhotoCell : UITableViewCell <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) IBOutlet UITableView *horizontalTableView;
@property (nonatomic, strong) NSArray *contentArray;

- (IBAction)photoButton:(id)sender;
@end

.m file:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    /// ----- code here to setup the cell, button, image, etc...

    // do something when the buttong is pressed
    [imageButton addTarget:self action:@selector(photoButton:) forControlEvents:UIControlEventTouchUpInside];

    return cell;
}

- (IBAction)photoButton:(id)sender 
{
    CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.horizontalTableView];
    NSIndexPath *hitIndex = [self.horizontalTableView indexPathForRowAtPoint:hitPoint];

    // do some stuff here to pull object data out of the contentArray
    NSLog(@"Image clicked, index: %d", hitIndex.row);
    // other non-relevant code snipped to keep this example short

    // next I want to present a modal view controller (lets call it PhotoAlbum) which is a TableViewController

    PhotoAlbum *photoAlbum = [[PhotoAlbum alloc] init];

    // below does not work, does not even autocomplete in Xcode. I believe its because I'm in a UITableViewCell and not a VC... Any suggestions here?
    [photoAlbum setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentModalViewController:photoAlbum animated:YES];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:30:38+00:00Added an answer on May 29, 2026 at 7:30 pm

    I’m not sure why you are recreating the button each time in the cell instead of changing the image, but let’s ignore that for now.

    You can connect all your buttons to the same action in your table view controller, this action can take a sender argument as usual.

    You add an action like so:

    [imageButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    

    This calls a method in your view controller with the signature:

     -(void)buttonPressed:(UIButton * sender)
    

    In this method, you can detect which row was clicked as follows:

    CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView];
    NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];
    

    And then perform whatever other actions you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.