UITableViewCellに少し問題があります。各カスタムセルには、UISwitchとUIButtonがあります。そして、ユーザーがUISwitchの値を変更するとき、button.hiddenプロパティをYESに設定したいと思います。
このメソッドでクリックされたUISwitchを見つけることができます。
- (IBAction)closeHour:(id)sender {
UISwitch *senderSwitch = (UISwitch *)sender;
UITableViewCell *switchCell = (UITableViewCell *)[senderSwitch superview];
NSUInteger buttonRow = [[resas indexPathForCell:switchCell] row];
NSLog("%d", buttonRow);
}
これは完全に機能しますが、同じインデックス(indexPath.row)でUIButtonを取得して、彼の非表示のプロパティを設定する方法がわかりません。各UIButtonにタグを設定することを考えましたが、あまり親しみがありません。
私のセルがどのように作成されたかがあります。誰かが私がここでいくつかのがらくたをしているのかどうか教えてくれるなら、それはとてもいいかもしれません:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier1 = @"Cell1";
static NSString *cellIdentifier2 = @"Cell2";
if ([typeOfData objectAtIndex:indexPath.row] == @"hour") {
TimeCell *cell = (TimeCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
if (cell == nil) {
cell = [[[TimeCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier1] autorelease];
UISwitch *isOpen = [[UISwitch alloc] initWithFrame:CGRectMake(300, 7, 0, 0)];
if ([self openOrCloseHour:[[[finalData objectAtIndex:indexPath.row] substringToIndex:2] intValue]])
isOpen.on = YES;
else {
isOpen.on = NO;
[isOpen addTarget:self action:@selector(closeHour:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:isOpen];
[isOpen release];
UIButton *add = [UIButton buttonWithType:UIButtonTypeContactAdd];
add.frame = CGRectMake(400, 3, 170, 40);
[add addTarget:self action:@selector(addResa:) forControlEvents:UIControlEventTouchDown];
[cell addSubview:add];
}
}
[cell.time setText:[finalData objectAtIndex:indexPath.row]];
return cell;
}
else
{
ResaCell *cell = (ResaCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
if (cell == nil) {
cell = [[[ResaCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier2] autorelease];
[cell.isConfirm setImage:[UIImage imageNamed:@"confirm.png"]];
[cell.nom setText:[finalData objectAtIndex:indexPath.row]];
[cell.prenom setText:[finalData objectAtIndex:indexPath.row]];
[cell.arrive setText:[finalData objectAtIndex:indexPath.row]];
}
return cell;
}
return nil;
}
参考までに、2種類のセルがあります。問題はTimeCellにあります。
誰かが解決策を持っていますか?