我创建自定义复选框在我的表格视图时,当我选择行时间没有改变我的复选框。请帮助我如何添加表格视图单元格中的复选框?
我的代码:
- (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
你在哪儿定义'checkButton''pLblCabType''pLblTariff'?以及为什么要从单元格视图中删除子视图,如果它已出列,然后为其分配值? – 2014-11-01 12:02:19
我正在创建检查按钮,PLblCabType,PlblTariff进入单元格视图。 – 2014-11-01 12:07:29
你已经创建了UITableViewCell的子类? – 2014-11-01 12:10:30