iphone - 在表格 View 中切换图像时如何采取任何行动?

标签 iphone ios ipad

我有一个带有复选标记按钮的表格 View 的应用程序。使用 UIcontroll 的子类化。使用这个

How to display a Subclass of UIControl on the screen它只会切换图像。在我的情况下,我有两个部分。当我选择第 0 部分上的按钮时,它必须取消选择所有其他已选择的按钮。仅适用于该按钮,而且我还需要知道选择了哪个按钮由用户。有人可以帮助我吗?

最佳答案

在 ui 元素之间进行通信的最简单方法是发布事件。因此,在这种情况下,您想要捕获触摸事件或复选框更改事件,然后发布一个您的按钮被选中的事件。在其他单元格中,监听事件,当另一个复选框被选中时,单元格将其复选框设置为取消选中。

在选择单元格中:

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:checkbox forKey:@"selectedCheckbox"];
   [[NSNotificationCenter defaultCenter] postNotificationName:@"checkboxSelected" object:nil userInfo: userInfo];               

在其他单元格中:
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearSelection) name:@"checkboxSelected:" object:userInfo];
... look in the 
-(void) checkboxSelected: (NSNotification *) note  {
    NSDictionary * userInfo = note.userInfo;
    checkbox = (UnMessage *)[userInfo objectForKey:@"selectedCheckbox"];
    if(checkbox == myCheckbox) return; // ignore
// deselect my checkbox...

在单元格上的 dealloc 上:
 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"checkboxSelected" object:nil];

关于iphone - 在表格 View 中切换图像时如何采取任何行动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13153855/

相关文章:

iphone - UITableViewCell 内的 UISlider 更新

iphone - 识别 UILabel 的调整字体大小

ios - 标签栏图标不显示?

ios - 在 iphone 中单击按钮时如何将文本字段/标签中的值添加到数组

iphone - iOSscrollview.bounces 使应用程序在 iOS 4.x 上崩溃

ios - UIViewController 的子类不捕获触摸事件

ios - 当变换属性不是恒等变换时如何调整 View 大小

ios - 泛型 'is not identical to' 错误

objective-c - 为什么 ARC 取消分配我的对象?

iphone - 如何实现动态的UIView mask ?