[英]UIButton target: action: Selector Argument
我有这个方法:
- (void)retweet:(NSString *)idString {
STTwitterAPI *twitter;
[twitter postStatusRetweetWithID:idString successBlock:^(NSDictionary *status) {
UIAlertView *retweetSuccess = [[UIAlertView alloc]initWithTitle:@"Retweeted!" message:@"You have retweeted this tweet." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[retweetSuccess show];
} errorBlock:^(NSError *error){
}];
}
我的tableview单元格中也有一个uibutton所以我正在使用[cell.retweetButton addTarget:self action:@selector(retweet:)forControlEvents:UIControlEventTouchUpInside];
如何使用我的idString作为方法参数与选择器的参数?
如果id字符串来自按钮,则将操作方法参数更改为paramButton并访问它。 如果它来自其他地方那么你需要简单地从它来自的地方获取它。
无论如何,你的action方法必须有:(UIButon *)paramButton参数。 ((id)发送者也可以接受作为替代)。
使用目标c关联对象
#import <objc/runtime.h>
static const void *idStringKey = &idStringKey;
@implementation UIButton (idString)
- (void)setIDString:(NSString *)idString
{
objc_setAssociatedObject(self, idStringKey, idString, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (NSString *)idString
{
return objc_getAssociatedObject(self, idStringKey);
}
@end
采用
cell.retweetButton.idString = @"Any string here"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.