当我选择时间没有更改我的复选框的行时,我在表格视图中创建了自定义复选框。请帮助我
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
@try {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[checkButton setFrame:CGRectMake(5, 5, 20, 20)];
[cell addSubview:checkButton];
pLblCabType = [[UILabel alloc]initWithFrame:CGRectMake(30, 5, 200, 20)];
[cell addSubview:pLblCabType];
pLblTariff = [[UILabel alloc]initWithFrame:CGRectMake(240, 5, 80, 20)];
[cell addSubview:pLblTariff];
}
[checkButton setImage:[UIImage imageNamed:[pArrImgBullet objectAtIndex:indexPath.row]] forState:UIControlStateNormal];
pLblCabType.text = @"Arul";
pLblTariff.text = @"Rs.1250";
return cell;
}
@catch (NSException *exception) {
NSLog(@"Exception Error is %@",exception);
}
@finally {
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
@try {
[checkButton setImage:[UIImage imageNamed:@"Bullet_Select.png"] forState:UIControlStateSelected];
[pArrImgBullet replaceObjectAtIndex:indexPath.row withObject:@"Bullet_Select.png"];
}
}
@catch (NSException *exception) {
NSLog(@"Exception Error is %@",exception);
}
@finally {
}
}
先谢谢, S.Arul
答案 0 :(得分:1)
尝试修改以下cellForRowAtIndexPath
方法: -
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"CellWithSwitch"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellWithSwitch"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
return cell;
答案 1 :(得分:0)