iOS:一个Cell中设置另外一个Cell中的button
2024-08-28 18:37:13
场景:
子类化Cell中有button,拥有选中式样,点击第一个Cell中的button后,Cell一中的button获得选中式样。可是当点击Cell二中的button时。Cell一中的button选中式样依旧存在,即同一时候存在两个选中的button。
解决方法:
在子类化的Cell中,定义一个
static UIButton *selectedButton;
必须是 static 静态变量。
然后在点击方法中。
- (void)headerButtonClickAction:(UIButton *)btn
{
selectedButton.layer.borderWidth = 0;
btn.layer.borderWidth = 2;
selectedButton = btn;
}
这种话我就能取到上次点击的button,
我设置的是边框宽度显示是否选中。自己能够依据自己的需求写demo。
这里要不用操心第一次运行时selectedButton为nil,为nil时。不会对程序产生影响。
最新文章
- 两年来的core折腾之路几点总结,附上nginx启用http2拿来即用的配置
- Microsoft Dynamics AX 2012: How to get Company,Customer and Vendor address in AX 2012
- 决策树 -- ID3算法小结
- 程序间数据共享与传递:EXPORT/IMPORT、SAP/ABAP Memory
- 第一百九十二天 how can I 坚持
- [转载]开机出现A disk read error occurred错误
- ZOJ Problem Set - 3758 素数
- selenium.common.exceptions.TimeoutException: Message: Screenshot: available via screen
- java多态 -- 猫狗案列
- 【Unity】Unity中C#与Android中Java的互相调用遇到的一些问题
- 15.C++-操作符重载
- 双向数据绑定原生js
- visual studio vode 汉化
- Windows Server2008 R2安装wampserver缺少api-ms-win-crt-runtime-l1-1-0.dll解决方案
- Python实现工厂模式
- 腾讯云cos封装
- Android 由 android:launchMode=";singleInstance“引发的界面无法返回的情况
- swift类型转换之Could not cast value of type xxx to xxx错误的一种特殊情况记录
- Android开发:《Gradle Recipes for Android》阅读笔记(翻译)6.2——DSL文档
- IE回车的一个怪异行为