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?
A
tagis anNSInteger, which is just atypedeffor plain oldint. Note that it is not an Object. I can’t see what type yourself.selectedTagis, but it seems to be an Object (e.g.NSNumber). To assign anNSNumbertoselectedTag, useself.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.