开发者

Store UIButton tag value

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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜