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 7924231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:39:23+00:00 2026-06-03T17:39:23+00:00

I have a view controller with 6 buttons on it. Each of these buttons

  • 0

I have a view controller with 6 buttons on it. Each of these buttons push a single table view controller which will be propagated with items depending on what value the button had. Lets say the buttons were ‘car’, ‘van’ etc. is it possible to remember the value of the button when the table view is pushed so that the twitter search can be based on the value handed over by the button i.e #car? I can do this with 6 different table views as I can just assign a viewDidLoad method to each based on the search but I would rather only do it once and allow the table view to ‘fill in’ the value on the button automatically. Here is my code:

- (void)fetchTweets
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data = [NSData dataWithContentsOfURL:
                        [NSURL URLWithString: @"https://api.twitter.com/1/statuses/public_timeline.json"]];

        NSError* error;

        tweets = [NSJSONSerialization JSONObjectWithData:data
                                                 options:kNilOptions
                                                   error:&error];

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
    });
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tweets.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TweetCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
    NSString *text = [tweet objectForKey:@"text"];
    NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"];

    cell.textLabel.text = text;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name];

    return cell;
}
  • 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-06-03T17:39:24+00:00Added an answer on June 3, 2026 at 5:39 pm

    Easy man. Set a public property on that TableViewController to hold that value:

    In the TVC .h file:

    @property(nonatomic,strong) NSString *selectedButtonText;
    

    And synthesize it in the TVC .m file

    @synthesize selectedButtonText;
    

    If you are using Storyboard, just make sure you have the segue wired up to the ViewController itself and NOT to the buttons and then in each of the buttons IBActions do something like:

    [self performSegueWithIdentifier@"mySegueID" sender:sender];
    

    In the prepareForSegueMethod (implement if you haven’t already:

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        if ([segue.identifier isEqualToString:@"mySegueID"]) {
            // Cast the sender as a UIButton to get the text
            UIButton *tappedButton = (UIButton *)sender
    
            MyTableViewController *mtvc = segue.destinationViewController;
            mtvc.selectedButtonText = tappedButton.titleLabel.text;
        }
    }
    

    Then do whatever you want to with that value in your TableViewController

    * EDIT *

    For a custom attribute on an object (like a UIButton). Add a new file to your project (I put them in a group called Custom Subclasses). This file should be of UIButton class. Name it TweetButton.

    Then replace what you have in TweetButton.h with this:

    import

    @interface TweetButton : UIButton
    @property(nonatomic, strong) NSString *buttonName;
    @end

    TweetButton.m should look like:

    import “TweetButton.h”

    @implementation TweetButton
    @synthesize buttonName;
    @end

    Then just change the parent class of each of those buttons to TweetButton instead of UIButton (this will be done in Interface Builder).

    Then in each of the IBActions, cast that button to type of TweetButton and access/set the name property.

    After going through all this, another idea would be to just add in a property (NSString) in the ViewController that is calling the segue (the one with the buttons) and set that to whatever you want and then use that to send to the destination VC.

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

Sidebar

Related Questions

I have a root view controller which has few buttons. On click of these
i have view controller which contains a button which show the image library ,if
I have view controller, into the view i have put a table view, and
Simply scenario -- I have two buttons both of which call the same controller/action.
I have a grouped table view that contains 3 sections and each row per
I have two view controller classes in my application delegate. I can change from
I have a view controller and I am intercepting the touches on links within
I have a view controller class that has to implement several protocols. Too keep
I have a view controller that gets presented modally and changes some data that
I have a view controller that has a tableView in it. When I set

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.