【问题标题】:ios add float property to UIButton or deriveios给UIButton添加float属性或者派生
【发布时间】:2013-05-25 20:26:10
【问题描述】:

我需要将纬度和经度存储到 UIButton 中,所以 2 个浮点数.. 我怎样才能做到这一点?? 我需要这个来使用地图上大头针中的坐标: 问题是按钮(实际上右边的箭头(>)是UIButton,而我用来捕捉点击的事件只有(id)sender作为参数,如果我有多个别针不是可能...

提前致谢

【问题讨论】:

  • 你为什么不直接使用annotaion?为什么要找一个按钮搜索“Map callout ios”
  • 我使用注释但是在按钮点击之后?
  • 你把按钮放在哪里?在地图上?按钮的作用是什么?

标签: iphone ios properties uibutton


【解决方案1】:

简单的答案:不要使用 UIButton,像这样使用 UIButton 的子类:

@interface MyButton : UIButton

@property (readwrite) float latitude;
@property (readwrite) float longitude;

@end

@implementation

@end

如果您在 XIB 文件中创建这些按钮,只需选择该按钮,并将其自定义类从 UIButton 更改为 MyButton,XIB 加载机制将为您处理其余的业务。

注意:如果您在 MKAnnotationView 中使用它,则最好关联实际注释或注释的 CLLocation,而不是存储各个坐标。

【讨论】:

  • 谢谢@david-doyle.. 我需要这个,因为我需要做这样的事情:cl.ly/image/0u3r3w3J2F2T/Image%202012.08.20%207:59:05%20PM.png 我需要点击汽车来获取路线
  • 它是怎么崩溃的?有崩溃日志吗?
  • -[UIButton setLongitude:]:无法识别的选择器发送到实例 0x18785ef0 2013-06-01 14:44:02.486 Salento[1236:1d903] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因: ' - [UIButton的setLongitude:]:发送到实例0x18785ef0无法识别的选择' ***第一掷调用堆栈:(0x2a6e012 0x20b8e7e 0x2af94bd 0x2a5dbbc 0x2a5d94e 0x2f3f9 0xf104c4 0xf227e9 0xf23b9f 0xf239da 0xf23df3 0xf0f764 0xf0f794 0xf11fad 0x2e693 0x10e3753 0x10e3b2f 0x10e3d54 0x10f7bd3 0x127e351 0x127e629 0x127e698 0x103e3b6 0x103e554 0xc737d8 0x2288014 0x22787d5 0x2a14af5 0x2a13f44 0x2a13e1b
  • 好吧,问题来了。您仍在某处使用 UIButton 。找到它的创建位置,并将其更改为子类。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多