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

  • Home
  • SEARCH
  • 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 3957908
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:32:54+00:00 2026-05-20T02:32:54+00:00

I apologize if this is a simple question but I’ve been unable to find

  • 0

I apologize if this is a simple question but I’ve been unable to find a sufficient solution and I’m driving myself a little crazy 😛

I’ve got an app with a number of buttons (40-50) on various views, and a dictionary should be built with a number of entries based upon which button has been pressed.

(For example, if Button 27 is pressed I’d build a Dict in viewController with:
Name -> John Smith
Address -> 1 Infinite Loop
Age -> 99
)

Obviously writing an action specific to each button is wrong.

What I’d like to do is to subclass UIButton (continuing with above example), adding Name, Address, and Age as instance variables to my custom Button and to set each of this instance variables when when the button is instantiated with an init:
Then, when that button is pressed, I can have a SINGLE buildDict:(id)sender action that is called by all the buttons, and simply populate the dictionary with sender.Name etc…

My question is: can I add fields to the attributes inspector in Interface Builder to set these values? If this is not possible, where can I find the button instantiation so I can set these values programmatically?

  • 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-20T02:32:55+00:00Added an answer on May 20, 2026 at 2:32 am

    you don’t want to put data that belongs to the model inside a view. And this sounds awfully complicated too.
    Insert data in interface builder? I feel lucky if I don’t have to edit tags for my views and you want to edit data in it?

    Seriously, make it right. Create a NSArray. 40 objects for 40 buttons. Use the plist editor to create the list of addresses and load that plist file into your code. This is the fastest and cleanest way to do this.

    Give each button a tag. (if you have to add 40 buttons I would do it in code anyway) and connect them to a IBAction. I would suggest you to give the first item a tag of 1000. A button without a tag behaves like a button with tag 0, and you don’t want this. And you don’t want to subtract 1 if you go from button to array index.

    - (IBAction)buttonPressed:(UIButton *)sender {
        // remember? tag 1000 equals index 0. 
        NSUInteger index = sender.tag - 1000;
        NSDictionary *object = [self.data objectAtIndex:index];
        // do whatever you want
    }
    

    No need to subclass anything. No need to violate the model-view-controller concept.

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

Sidebar

Related Questions

This question may seem extremely noob-ish, I apologize. I've been periodically attempting for the
Ok, this is a very simple question. I am actually 90% sure I know
This is probably something very simple but I'm not getting the results I'm expecting.
If I had a normal website this would be a simple enough fix... but
Im not sure if this is the correct forum for this, if not I
I am trying to make a regex that matches all occurrences of words that
I was playing around with list comprehensions to get a better understanding of them
Possible Duplicate: Pointer to local variable I've read a lot of other topics on
I would like to create an utility application that has a navigation based flipside,
I've used the following in the CSS file of the website. It works on

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.