我創建自定義複選框在我的表格視圖時,當我選擇行時間沒有改變我的複選框。請幫助我如何添加表格視圖單元格中的複選框?
我的代碼:
- (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