简体   繁体   English

在AccessoryView中设置带有图像的按钮

[英]Setting a Button with an image in the AccessoryView

I would like to customize the image in the accessory views of some tables while allowing to pass the table and indexPath to the accessoryButtonTappedForRowWithIndexPath callback including the clicked table. 我想在某些表的附件视图中自定义图像,同时允许将表和indexPath传递给包括clicked表在内的annexButtonTappedForRowWithIndexPath回调。 I used to employ the UIControl+Blocks.h class here reported: 我曾经在这里报道过使用UIControl + Blocks.h类:

 @implementation UIControl (Blocks)
 - (void)addEventHandler:(ActionBlock)handler forControlEvents:  (UIControlEvents)controlEvents
{
    objc_setAssociatedObject(self, &UIButtonHandlerKey, handler, OBJC_ASSOCIATION_COPY_NONATOMIC);
   [self addTarget:self action:@selector(callActionHandler:event:)   forControlEvents:controlEvents];
}
- (void)callActionHandler:(id)sender event:(id)event
{
   ActionBlock handler = (ActionBlock)objc_getAssociatedObject(self, &UIButtonHandlerKey);
   if (handler) {
       handler(sender, event);
   }
}
@end

But it started behaving weirdly by sometimes returning the button in the place of the event so crashing my app when I try to get allTouches and so I am fervidly looking for a replacement. 但是它有时表现得很奇怪,有时会在事件发生的地方返回该按钮,因此当我尝试获取allTouches时,我的应用程序崩溃了,因此我很想寻找一个替代品。

I also tried replacing the original (i) accessory button, but in this way I also lose the accessibilityLabel. 我还尝试更换了原始(i)附件按钮,但是这样我也失去了accessibilityLabel。 Please help. 请帮忙。

我预见到了表重新加载的问题,从而恢复了旧的解决方案,以防按钮发疯并开始将自身发送为控件事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自定义accessoryView图像和accessoryButtonTappedForRowWithIndexPath - Custom accessoryView image and accessoryButtonTappedForRowWithIndexPath UITableView 单元格附件视图图像问题 - UITableView cell accessoryView image issue 自定义UITableViewCell accessoryView按钮在REAL设备上不可见 - Custom UITableViewCell accessoryView button invisible on REAL device 从UITableViewCell的附件视图中的自定义按钮获取索引路径 - Get the indexpath from custom button in accessoryView of a UITableViewCell 如何检查uitableviewcell附件视图是否包含图像 - how to check uitableviewcell accessoryView contains image or not 为UITableViewCell的accessoryView使用自定义图像并让它响应UITableViewDelegate - Using a custom image for a UITableViewCell's accessoryView and having it respond to UITableViewDelegate 在滚动期间设置UITableViewCell按钮图像值 - Setting UITableViewCell button image values during scrolling UIButtonTypeRoundedRect作为accessoryView - UIButtonTypeRoundedRect as an accessoryView 当不应该仅对可重复使用的单元格显示cell.accessoryView图像时出现 - cell.accessoryView image appearing when it shouldn't for reusable cells only 在表格中将自定义的附件视图更改为Swift 3中的其他附件视图 - Change a custom accessoryView in a table to a different accessoryView in Swift 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM