ios - 为 UIButton 设置多个自定义参数

标签 ios objective-c uibutton

.... Call to webservice
     NSArray *someValues = [results valueForKey:@"someKey"];
    [button setTitle:[NSString stringWithFormat:@"%@", [someValues objectAtIndex:i]] forState:UIControlStateNormal];
} // end

-(void)btnPressed:(id)sender
{
    UIButton *button = sender;
    button.currentTitle; // Title comes back just fine
}

I want to be able to add more parameters so I can get them back on the click method. So example
button.someParam = @"My name"
...
// once clicked
UIButton *button = sender;
button.someParam // gets back "My Name"

目前我可以设置一个自定义标题并恢复正常。我想添加更多值以与我的按钮一起传递。这可能吗?这些值正在动态返回。我知道我可以设置标签 #,但这无助于我从我尝试过的内容中获取自定义值。

最佳答案

您想将属性添加到 UIButton

一种方法是创建一个 UIButton 子类并在其中添加属性。然后使用该子类代替常规的 UIButton

关于ios - 为 UIButton 设置多个自定义参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30113706/

相关文章:

html - 媒体查询仅在 Safari/iOS 设备上覆盖其他媒体查询

ios - 无法在代码中更改 xib 文件的 Root View 大小。 iOS

ios - 运行 pod install 时出错 - 在目标 `iOS` 上自动分配版本 `8.0` 的平台 `Runner`

iphone - NSFetchedResultsController 中的 NSPredicate 抛出 EXC_BAD_ACCESS

ios - 适用于 iOS 的 Dropbox 集成

ios - 使用 UiButton 反复更改 UILabel 文本

javascript - 用于从 ios 缓存加载视频源的 Cordova 文件插件

objective-c - AFNetworking 没有弧线的旧版本

xcode - UI 元素 setAction 和 setTarget 不工作

iOS - 从 View 的 uibutton 关闭子类 UIView