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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:44:30+00:00 2026-06-17T09:44:30+00:00

EDIT: I apologize for wasting time, the erorr had nothing to do with what

  • 0

EDIT: I apologize for wasting time, the erorr had nothing to do with what I’m taking about but rather some logic in my code that made me believe this was the cause. I’m awarding Kevin with the correct answer since using his idea to pass the whole AuthorSelectionView, and his note on correcting the NSNumer mistake. Sorry about that.

I’ve been trying to figure this out for hours, and even left it alone for a day, and still can not figure it out…

My situation is as follows:

I’ve created a custom class that implements ‘UIView’ and made this class into a protocol as follows:

custom UIView h file

@protocol AuthorSelectionViewDelegate <NSObject>
-(void)AuthorSelected:(NSNumber *)sender;
@end

#import <UIKit/UIKit.h>

@interface AuthorSelectionView : UIView

@property (nonatomic,assign) id<AuthorSelectionViewDelegate> delegate;

@property (strong,retain) NSNumber *authorID;

- (id)initWithFrame:(CGRect)frame withImage:(UIImage *)img withLabel:(NSString *)lbl withID:(int)authorID ;

@end

the implementation…

    - (id)initWithFrame:(CGRect)frame withImage:(UIImage *)img withLabel:(NSString *)lbl withID:(int)authorID
    {
        self = [super initWithFrame:frame];
        if (self) {
            self.authorID = [[NSNumber alloc] initWithInt:authorID]; //used to distinguish multiple instances of this class in a view.

            ...

        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, FRAMEWIDTH, FRAMEHEIGHT)];
        [button addTarget:self action:@selector(CUSTOMBUTTONCLICK) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
    }
return self;
}

    - (void) CUSTOMBUTTONCLICK
    {
        [self.delegate performSelector:@selector(AuthorSelected:) withObject:self.authorID];
    }

Now the method in my delegate object gets called just fine, but my major problem here is that something is going on with the object being pass through when i have multiple instances of the AuthorSelected class alloc’d.. (the NSNumber authorID). I’m getting some weird behavior with it. It seems almost random with the value being passed, but i’m detecting some pattern where the value passed through is coming up late..

thats confusing so ill try to explain:
I create two instances of the AuthorSelected view, one with authorID=1 and the other with authorID=2.

On the first press, lets say i press the first button, i’ll get 1 as expected.

On the second press, if I press the 1st custom button, i’ll get ‘1’, but if i press the second i’ll still get 1.

On the third go, either button will give me back ‘2’

I feel like this is some issue with pointers since that has always been a weak point for me, but any help would be greatly appreciated as I can not seem to figure this one out.

Thank you!

EDIT:

as requested here is how I create the AuthorSelectionView Objects...

AuthorSelectionView * asView01 = [[AuthorSelectionView alloc]
initWithFrame:CGRectMake(0, 0, FRAMEWIDTH, FRAMEHEIGHT)
withImage:userPic1
withLabel:randomUserName
withID:1];

asView01.delegate = self;

AuthorSelectionView * asView02 = [[AuthorSelectionView alloc]
initWithFrame:CGRectMake(0, 0, FRAMEWIDTH, FRAMEHEIGHT)
withImage:userPic2
withLabel:randomUserName2
withID:2];

asView02.delegate = self;

A detail that may be important:

As soon as i click on one of these custom views, my code is set to (for now) call the method that runs the above AuthorSelectionView alloc code, so that i can refresh the screen with the same layout, but with different userpic/userName. This is poor design, I know, but for now I just want the basic features to work, and will then worry about redrawing. I metion this tidbit, becuase I understand that objective-c ‘layers’ veiws on top of eachother like paint on a canvas, and had a thought that maybe when I click what I think may be my 2nd button, its really ‘clicking’ the layer beneath and pulling incorrect info.

  • 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-17T09:44:31+00:00Added an answer on June 17, 2026 at 9:44 am

    Your description of the problem is a bit confusing, but this line in your init is very clearly wrong:

    self.authorID = [self.authorID initWithInt:authorID];
    

    In -init, your property self.authorID defaults to nil, so the expression [self.authorID initWithInt:authorID] is equivalent to [nil initWithInt:authorID], which evaluates back to nil. So you should actually be seeing nil in your action. You probably meant to say self.authorID = [NSNumber numberWithInt:authorID]

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

Sidebar

Related Questions

EDIT 1 I apologize but after reading the 2 suggested articles I still don't
EDIT: I was an idiot. I simply had an image that was vertically long,
I apologize if this is a duplicate but I did not find anything that
Hopefully there is not a lot of code, so I apologize for that. I
EDIT: damien the unbeliever, my apologies, trying to be terse I omitted saying that
EDIT: See my answer below--> I am wanting to have a view that when
EDIT: iam using ajax to load text in my content that is why onload
Edit : Note that, as Daniel and latkin noted in an answer and a
EDIT : It turned out that this can only be done through an external
I apologize if this question is vague, but I want to build a drop

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.