Corona中文站

强大、易学的跨平台(iOS/Android)开发框架。QQ群1:74390406(满) 群2:221929599

导航

UITableView中显示单选效果
- (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;
}
<< 如何自定义view controller及动态切换view [复制链接]iOS关于隐藏键盘的几段代码 >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

Powered By Z-Blog 1.8 Walle Build 100427 Copyright 2011-2015 BuildApp.Net. All Rights Reserved.