У меня небольшая проблема в UITableViewCell. Каждая пользовательская ячейка имеет UISwitch и UIButton. И когда пользователь меняет значение UISwitch, я хотел бы установить свойство button.hidden в значение YES.UISwitch и UIButton в UITableViewCell, как их идентифицировать
я могу найти, какую UISwitch была нажата с помощью этого метода:
- (IBAction)closeHour:(id)sender {
UISwitch *senderSwitch = (UISwitch *)sender;
UITableViewCell *switchCell = (UITableViewCell *)[senderSwitch superview];
NSUInteger buttonRow = [[resas indexPathForCell:switchCell] row];
NSLog("%d", buttonRow);
}
Этой работа отлично, но я не знаю, как получить UIButton в том же индексе (indexPath.row), чтобы установить его скрытые имущество. Я думал об установке тега в каждом 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;
}
Для информации я получил два типа клеток. Проблема в TimeCell.
У кого-нибудь есть решение?
Здравствуйте. Взгляните на мой последний ответ (http://stackoverflow.com/questions/3888771/edit-a-boolean-value-on-click-on-a-buton-at-customized-table-view-cell). Ваша проблема аналогична. Но вам нужно дополнительно получить View с viewWithTag: ^^ Good Luck – Vinzius
Спасибо за ваш ответ, но я не могу этого сделать. Этот метод является вызовом UISwitch, а не UIButton, поэтому отправитель является UISwitch, и нет возможности идентифицировать UIButton. Может быть, я ошибаюсь, я потерпел неудачу. – foOg