UItableViewCell一些实用细节与技巧
来源:互联网 发布:网络投诉管理办法 编辑:程序博客网 时间:2024/05/16 11:56
1.加上这句代码就没有一直选中状态了,只在点击时有个状态
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];}
2.UITableViewCell可以选择但无选择状态
cell.selectionStyle = UITableViewCellSelectionStyleNone;状态有以下几种typedef NS_ENUM(NSInteger, UITableViewCellSelectionStyle) { UITableViewCellSelectionStyleNone, UITableViewCellSelectionStyleBlue, UITableViewCellSelectionStyleGray, UITableViewCellSelectionStyleDefault NS_ENUM_AVAILABLE_IOS(7_0)};
3.UITableViewCell设为不可选中(会影响一些设置)
cell.userInteractionEnabled = NO;
4.UITableViewCell设成选中状态
[tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section] animated:NO scrollPosition:UITableViewScrollPositionNone];
5.UITableViewCell在右侧添加Switch(开关)
可以自己先定义一个开关,然后直接加到cell的accessoryView上即可
-(UISwitch *)blockSwitch{ if (_blockSwitch == nil) { _blockSwitch = [[UISwitch alloc]init]; _blockSwitch.onTintColor = RGBCOLOR(63, 125, 194); [_blockSwitch addTarget:self action:@selector(blockSwitchChanged:) forControlEvents:UIControlEventValueChanged];return _blockSwitch;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{......省略cell.textLabel.text = @"消息免打扰";cell.accessoryView = self.blockSwitch; //switch}
6.Cell的下划线
cell下划线默认左侧有一段空白,想改变下划线可以用下面代码
//在viewDidLoad中 -(void)viewDidLoad{if ([mTableView respondsToSelector:@selector(setSeparatorInset:)]) { [mTableView setSeparatorInset:UIEdgeInsetsZero]; } if ([mTableView respondsToSelector:@selector(setLayoutMargins:)]) { [mTableView setLayoutMargins:UIEdgeInsetsZero]; } }//在tableView的代理方法中- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row==5){ if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } }else{ if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0,10,0,0)]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsMake(0,10,0,0)]; }} }//这样第row == 5的cell里线就顶到头了
0 0
- UItableViewCell一些实用细节与技巧
- ctags 的一些实用细节!!
- ctags 的一些实用细节!!
- ctags 的一些实用细节!!
- Python 一些细节技巧汇总
- UITableView的一些细节技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- JavaScript实用的一些技巧
- [LeetCode]problem 80. Remove Duplicates from Sorted Array II
- Halting problem(停机问题)
- mysql距离函数st_distance
- TCP_CORK
- LightOJ 1045 I - Digits of Factorial
- UItableViewCell一些实用细节与技巧
- 构造函数与析构函数中不调用虚函数
- 阿里音乐-比赛记录(1)
- Ubuntu 使用crontab定时任务
- Prim算法C语言实现
- android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )屏幕适配
- 调试时发现的一个奇怪的现象,static int = 0时无法自增
- Android_日期选择器DatePickerDialog、时间选择器TimePickerDialog
- 解决You need to use a Theme.AppCompat theme (or descendant) with this activity.