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:

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.

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.

You should really change that delegate method to pass the AuthorSelectionView* as the parameter instead of the NSNumber*. That's the standard way to do delegates, and your delegate can still get the authorID simply by asking the AuthorSelectionView* for it.
–
Kevin BallardJan 8 '13 at 20:15

Show us how you create the AuthorSelectionView objects.
–
Ramy Al ZuhouriJan 8 '13 at 20:28

I've made this adjustment, still getting unexpected results. I will update my original post with a few more details that might be important.
–
Gagan SinghJan 8 '13 at 20:29

3 Answers
3

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]

Whoops you are totally correct. I initially had it as [self.authorID initWithInt:authorID];] but was playing around trying to fix the issue and must have forgot about that line. Thank you, i'll correct it in the Original Post
–
Gagan SinghJan 8 '13 at 20:13

thank you for pointing this out, but this error was just a posting error, the code should read: 'self.authorID = [[NSNumber alloc] initWithInt:authorID];' which i've updated in the original post
–
Gagan SinghJan 8 '13 at 20:17