tags:

views:

22

answers:

1

Need to store the tag from a clicked button:

- (IBAction)buttonClicked:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectedImage = [_images objectAtIndex:button.tag];
}

Works OK.

- (IBAction)buttonClicked:(id)sender {
    UIButton *button = (UIButton *)sender;
    self.selectedImage = [_images objectAtIndex:button.tag];
    self.selectedTag = button.tag;
}

Gives "makes pointer from integer without cast".

How should I reference button.tag correctly?

+1  A: 

A tag is an NSInteger, which is just a typedef for plain old int. Note that it is not an Object. I can't see what type your self.selectedTag is, but it seems to be an Object (e.g. NSNumber). To assign an NSNumber to selectedTag, use self.selectedTag = [NSNumber numberWithInteger:button.tag];

Additionally, if you use four blanks at the beginning of each line of code, StackOverflow is going to indent it and use basic syntax highlighting.

muffix
self.selectedTag is an NSInteger so that I can use it in a switch statement.
MartinW