UITableViewCell 中的单选控制 UITableViewCellAccessoryCheckmark
2015-11-13 12:35
381 查看
需要注意的是这个函数,用来设置cell的UITableViewCellAccessoryType 属性--这里用到UITableViewCellAccessoryCheckmark
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==currentIndex){
return UITableViewCellAccessoryCheckmark;
}
else{
return UITableViewCellAccessoryNone;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if(indexPath.row==currentIndex){
return;
}
NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:currentIndex
inSection:0];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if (newCell.accessoryType == UITableViewCellAccessoryNone) {
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
newCell.textColor=[UIColor blueColor];
}
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark) {
oldCell.accessoryType = UITableViewCellAccessoryNone;
oldCell.textColor=[UIColor blackColor];
}
currentIndex=indexPath.row;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
}
if(indexPath.row==currentIndex){
cell.textColor=[UIColor blueColor];
}
else{
cell.textColor=[UIColor blackColor];
}
cell.text=@"ttttttttttttttt";
return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==currentIndex){
return UITableViewCellAccessoryCheckmark;
}
else{
return UITableViewCellAccessoryNone;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if(indexPath.row==currentIndex){
return;
}
NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:currentIndex
inSection:0];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if (newCell.accessoryType == UITableViewCellAccessoryNone) {
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
newCell.textColor=[UIColor blueColor];
}
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark) {
oldCell.accessoryType = UITableViewCellAccessoryNone;
oldCell.textColor=[UIColor blackColor];
}
currentIndex=indexPath.row;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
}
if(indexPath.row==currentIndex){
cell.textColor=[UIColor blueColor];
}
else{
cell.textColor=[UIColor blackColor];
}
cell.text=@"ttttttttttttttt";
return cell;
}
相关文章推荐
- msbuild,Build failed with Error MSB3073 exited with code 1
- UIview 和 CALayer
- NSString+NSMutableString+NSValue+NSAraay用法汇总
- Redrain duilib中事件委托存在的问题
- 关于Selector方法需要多个参数的问题解决方法
- rpmbuild SPEC语法
- CSS3 Media Queries
- UE4蓝图案例:制作点击场景中的物体弹出UMG界面
- openwebrtc build framework (Building OpenWebRTC with Cerbero)
- hdu 5538 House Building 巧妙利用数组来模拟(2015ACM/ICPC亚洲区长春站-重现赛 )
- UITableView横向滚动
- iOSiOS开发Xcode报错之:You must rebuild it with bitcode enabled (...
- 大鱼吃小鱼游戏-fruit.js
- Android中关于Volley的使用,从RequestQueue开始来深入认识Volley
- HBuilder 快捷键
- UITableView去掉分隔线
- [LeetCode]76. Permutation Sequence全排列序列
- Confluence 安装破解
- 【iOS】uitextfield
- IOS学习之 UIStackView入门