tableview点击变cell背景颜色问题

jcskey jcskey 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
功能就是多选效果,点击其中一个 背景变色,在点击就回变回白色,求教
1,一共18个数组,点击第一个cell改变颜色的时候第15个也自动变更颜色,第二个16个也回同事变色,第三个17个也回,
代码如下
[code=objc]@interface fivetableview ()

@end

@implementation fivetableview
@synthesize dlists;
@synthesize dellist;

NSInteger i;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{

[super viewDidLoad];
dellist=[[NSMutableArray alloc]initWithCapacity:30];
dlists=[[NSMutableArray alloc] initWithCapacity:30 ];
[dlists addObject:@"大众化的"];
[dlists addObject:@"线条硬朗的"];
[dlists addObject:@"流线型的"];
[dlists addObject:@"大气的"];
[dlists addObject:@"时尚的"];
[dlists addObject:@"简约的"];
[dlists addObject:@"有力量感的"];
[dlists addObject:@"张扬的"];
[dlists addObject:@"霸气的"];
[dlists addObject:@"动感的"];
[dlists addObject:@"稳重的"];
[dlists addObject:@"优雅的"];
[dlists addObject:@"粗犷的"];
[dlists addObject:@"创新的"];
[dlists addObject:@"中性的"];
[dlists addObject:@"活力的"];
[dlists addObject:@"经典的"];
NSLog(@"%d",[dlists count]);
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.

return [dlists count];
//return [dlists count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell4";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSInteger row = [indexPath row];
cell.textLabel.text = [self.dlists objectAtIndex:row];
NSLog(@"row=%d",row);
return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];

@end
[/code]
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
jcskey
iOS 29,038 成员 12,459 内容