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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:25:27+00:00 2026-05-20T09:25:27+00:00

I’m spinning in circles on the best way to implement this, so maybe you

  • 0

I’m spinning in circles on the best way to implement this, so maybe you can help me out:

How can I make it so when the UIButton responds to the selector highlightImage, it also can set the desired challengeId = the index of my appDelegate.availableArray?

In my cellForRowAtIndexPath method, I’m creating a UIScrollView with buttons:

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];
    [scrollView setContentSize:CGSizeMake(500, 78)];

    [self createScrollButtons];

    [[cell contentView] addSubview:scrollView];

My createScrollButtons loops and creates buttons in the scrollView as so, looping over the number of elements in my availableArray

- (void) createScrollButtons
{
    SuperHeroGameAppDelegate *appDelegate = (SuperHeroGameAppDelegate *)[[UIApplication sharedApplication] delegate];

    int x = 0;
    int y = 0;
    NSLog(@"Challenge array = %@",appDelegate.availableArray);
    for (int i = 0; i < [appDelegate.availableArray count]; i++) {
        NSLog(@" ID= %d", [[[appDelegate.availableArray objectAtIndex:i]valueForKey:@"id"] intValue]);
        [self createButtonAtX:x AndY:y withChallenge:[[appDelegate.availableArray objectAtIndex:i]valueForKey:@"id"]];
        x += 90;
    }

}

createButtonAtX andY withChallenge is called for each element inavailableArray`, positioning them correctly along the scrollView.

- (void)createButtonAtX:(int) x AndY:(int) y withChallenge:(id)challengeId
{
    CGRect buttonRect = CGRectMake(x, y, 80, 78); 
    ChallengeButton *capeButton = [ChallengeButton buttonWithType:UIButtonTypeCustom];

    [capeButton setBackgroundColor:[UIColor clearColor]];
    [capeButton setFrame:buttonRect];

    [capeButton addTarget:self action:@selector(highlightImage:) forControlEvents:UIControlEventTouchUpInside];

    UIImage *capeImage = [UIImage imageNamed:@"CapePower.png"];
    [capeButton setBackgroundImage:capeImage forState:UIControlStateNormal];

    [scrollView addSubview: capeButton];
}

highlightImage is called as each buttons selector, to determine which button is pressed. (and ideally with element from the availableArray that button is associated with)… I’ve subclasses UIButton and added an int value to be able to call [sender setChallengeId:]

- (void) highlightImage:(id)sender
{

    if([sender isSelected] == NO){
        [sender setSelected:YES];

        [sender setChallengeId:selectedChallenge];
        NSLog(@"sender = %d",[sender challengeId]);     
        UIImage *selectedImage = [UIImage imageNamed:@"PowerBarHand.png"];
        [sender setBackgroundImage:selectedImage forState:UIControlStateSelected];

    }
    else {
        [sender setBackgroundImage:[UIImage imageNamed:@"HandstandPower.png"] forState:UIControlStateNormal];   
        [sender setSelected:NO];
        selectedChallenge = 0;
    }
}

My problem is I cannot figure out how to get the appDelegate’s availableArray element INTO my highlightImage, as UIButton’s [capeButton addTarget:challengeId action:@selector(highlightImage:) forControlEvents:UIControlEventTouchUpInside] will not allow me to pass the challengeId from the loop earlier in the flow.

I am able to pass any integer value to setChallengeId, and it is handling as expected. I just need to get the appDelegate.availableArray id value from the loop.

Any direction would be great!:)

  • 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-20T09:25:28+00:00Added an answer on May 20, 2026 at 9:25 am

    You get availableArray into highlightImage: the same way you got it into createScrollButtons:

    SuperHeroGameAppDelegate *appDelegate = (SuperHeroGameAppDelegate *)[[UIApplication sharedApplication] delegate];
    

    and then access appDelegate.availableArray.

    I think that’s not the question you actually meant to ask, though. I think what you want is to call setChallengeId: on each ChallengeButton as you create it in createButtonAtX:AndY:withChallenge:. Then in highlightImage: do selectedChallenge = [sender challengeId] rather than [sender setChallengeId:selectedChallenge].

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.