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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:46:44+00:00 2026-05-21T21:46:44+00:00

I was wondering if it is possible to add a second tag to a

  • 0

I was wondering if it is possible to add a second tag to a UIButton? I’ve created a number of buttons programatically in a for-loop and need a reference to the number of the button (e.g. 0, 1, 2) and another reference (integer) in which I store a reference to the page the button links to (e.g. 22, 30, 49). The numbers are not related so I can’t determine the first through the second.

This is what I’d like to have:

for (int k=0; k < numberOfTabs; k++) // k < 4 (e.g. 3 < 4) 
{
    UIButton* btn = [[[UIButton alloc] initWithFrame:frame] autorelease];
    btn.tag = k;

btn.tag2 = someReference;

    btn.frame = CGRectMake(-10, 0, buttonWidth, buttonHeight);
    [btn    addTarget:self
            action:@selector(tabAction:)
  forControlEvents:UIControlEventTouchUpInside];
    [btn    addTarget:self
                action:@selector(tabDelete:)
      forControlEvents:UIControlEventTouchDragOutside];
/...

Any suggestions would be very much appreciated.

  • 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-21T21:46:44+00:00Added an answer on May 21, 2026 at 9:46 pm

    Why not store the second (any more, if needed) parameters in something like an NSMutableArray?

    NSMutableArray *button_to_page = [[NSMutableArray alloc] init];
    
    ...
    
    for(...)
    {
    
    // Your button creation code
    
    [button_to_page addObject:[NSNumber numberWithInt:my_button.tag];
    
    }
    

    You can get your page number at any time by simply indexing into the button_to_page array.
    You can also search the array for a page number and get the button index (if needed).

    Now, having said that, here you are creating a new NSNumber object for each button’s page tag and also carrying around an NSMutableArray to boot. I really think that subclassing UIButton is the way to go. I don’t like the idea of encoding stuff into the single tag unless there’s a real compelling reason. If you subclass you are still keeping the UIButton pretty lightweight and all your data is encapsulated within the same object very cleanly:

    MultiTag_UIButton.h

    #import <Foundation/Foundation.h>
    
    @interface MultiTag_UIButton : UIButton {
    
    }
    @property (nonatomic, assign) int page;
    
    @end
    

    MultiTag_UIButton.m

    #import "MultiTag_UIButton.h"
    
    @implementation MultiTag_UIButton
    
    @synthesize page;
    
    @end
    

    It really is that simple, you don’t have to write any code, just add the page property and you are off to the races. Then you can do this:

    MultiTag_UIButton *test_button = [[MultiTag_UIButton alloc] init];
    
    test_button.tag = 1;
    test_button.page = 23;
    
    NSLog(@"tag %i  page %i", test_button.tag, test_button.page);
    
    [test_button release];
    

    Clean and simple. Realistically you’d have to do a little more in the new class, but you get the idea.

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

Sidebar

Related Questions

Hi im wondering if its possible to add a asp button to the code
I was wondering if its possible to add custom header with classic asp. In
I was wondering if it is possible to add an icon to the iPhone
I'm wondering if it is possible to add cell content to a uitableview based
I was wondering if its possible to directly cast objects within a foreach loop.
i'm wondering if it's possible to add a php file in your themes folder
I was wondering if it is possible to add multiple generic constraints? I have
I was wondering if it possible to add constants to php before any scripts
I am wondering whether it is possible to add fields to objects dynamically. For
I was wondering if it is possible to add a menu resource to a

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.