假设我有一个要添加到地图视图中的注释对象的按钮:
AnnotationButton* rightButton = [AnnotationButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
您会注意到该按钮在showDetails
单击时会调用该函数。
显示详细信息被定义为- (void)showDetails:(id)sender;
并接收一个发送者。有没有办法发送更多变量,或关联不同的发件人?原因是我希望单击的按钮告诉我哪个注释与该按钮相关联。将注释视为在创建按钮的上下文中可用的其他对象。
我考虑过继承 UIButton 类,然后在其中存储其他信息,但这似乎是一种 hack。
有任何想法吗?