チェックボックスでテーブルビューを作成しています。UIButtons を使用してチェックボックスを実装しましたが、問題なくチェックおよびチェック解除できます。「すべて選択/選択解除」ボタンを作成しようとしたときに問題が発生し、これが結果のコードです。
-(IBAction)select:(id)sender{
if (all==YES) {
all=NO;
}
else {
all=YES;
}
[tblPeticiones reloadData];
}
問題は、テーブルがデータをリロードしないことです。何か案が?ありがとうございます。
編集:私はこのようなデータをロードします
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Datos
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSString *fInicio = [dateFormatter stringFromDate:[(MAP_Gastos_CiberTRIPS *)[m objectAtIndex:indexPath.row] DEP_DATE]];
NSString *loc = [(MAP_Gastos_CiberTRIPS *)[m objectAtIndex:indexPath.row] LOCATION];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setCurrencyCode:@"EUR"];
[formatter setLocale:[NSLocale currentLocale]];
NSString *precio = [formatter stringFromNumber:aux];
//Vista
NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row];
CustomTVC *cell = (CustomTVC *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[CustomTVC alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
//CheckBox
UIButton *checkButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[checkButton setFrame:CGRectMake(10, 10, 23, 23)];
if (todos==NO) {
[checkButton setBackgroundImage:[[UIImage imageNamed:@"checkNO.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
checkButton.tag = 0;
}
else {
[checkButton setBackgroundImage:[[UIImage imageNamed:@"checkSI.png"] str etchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
checkButton.tag = 1;
}
[checkButton addTarget:self action:@selector(checkAction:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:checkButton];
[cell.contentView addSubview:checkButton];
//fecha
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(40, 0, 70.0,tableView.rowHeight)] autorelease];
[cell addColumn:0];
label.tag = 1;
label.font = [UIFont boldSystemFontOfSize:12.0];
label.text = fInicio;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor blackColor];
//label.backgroundColor = [UIColor whiteColor];
label.autoresizingMask = UIViewAutoresizingNone | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
if (indexPath.row % 2 == 0){
label.backgroundColor = [UIColor colorWithRed:233.0/255.0
green:233.0/255.0
blue:233.0/255.0
alpha:1.0];
} else {
label.backgroundColor = [UIColor clearColor];
}
//localización
label = [[[UILabel alloc] initWithFrame:CGRectMake(115, 0, 75.0,tableView.rowHeight)] autorelease];
[cell addColumn:180];
label.tag = 2;
label.font = [UIFont boldSystemFontOfSize:12.0];
label.text = loc;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor blackColor];
//label.backgroundColor = [UIColor whiteColor];
label.autoresizingMask = UIViewAutoresizingNone | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
if (indexPath.row % 2 == 0){
label.backgroundColor = [UIColor colorWithRed:233.0/255.0
green:233.0/255.0
blue:233.0/255.0
alpha:1.0];
} else {
label.backgroundColor = [UIColor clearColor];
}
}
return cell;
}