UITableViewにて、Cell内にComboBoxを作ったら、なぜか反転してしまいます・・・。
上記の画像のように、Cellを選択するたびに、表示が反転してしまいます。
これが、UITableViewのdidSelectRowAtIndexPathです。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath section]) {
case 1: {
switch ([indexPath row]) {
case 0:
{
DropDownCell *cell = (DropDownCell*) [tableView cellForRowAtIndexPath:indexPath];
NSIndexPath *path0 = [NSIndexPath indexPathForRow:[indexPath row]+1 inSection:[indexPath section]];
NSIndexPath *path1 = [NSIndexPath indexPathForRow:[indexPath row]+2 inSection:[indexPath section]];
NSIndexPath *path2 = [NSIndexPath indexPathForRow:[indexPath row]+3 inSection:[indexPath section]];
NSArray *indexPathArray = [NSArray arrayWithObjects:path0, path1, path2, nil];
if ([cell isOpen])
{
[cell setClosed];
dropDown1Open = [cell isOpen];
[tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationTop];
}
else
{
[cell setOpen];
dropDown1Open = [cell isOpen];
[tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationTop];
}
break;
}
default:
{
dropDown1 = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text];
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:[indexPath section]];
DropDownCell *cell = (DropDownCell*) [tableView cellForRowAtIndexPath:path];
[[cell textLabel] setText:dropDown1];
NSIndexPath *path0 = [NSIndexPath indexPathForRow:[path row]+1 inSection:[indexPath section]];
NSIndexPath *path1 = [NSIndexPath indexPathForRow:[path row]+2 inSection:[indexPath section]];
NSIndexPath *path2 = [NSIndexPath indexPathForRow:[path row]+3 inSection:[indexPath section]];
NSArray *indexPathArray = [NSArray arrayWithObjects:path0, path1, path2, nil];
[cell setClosed];
dropDown1Open = [cell isOpen];
[tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationTop];
break;
}
}
}
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
といった感じなのですが、念のためcellForRowAtIndexPathも載せておきます。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil){
switch ([indexPath section]) {
case 0:{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.textLabel.text = @"first";
break;
}
case 1:{
switch ([indexPath row]) {
case 0: {
DropDownCell *cell = (DropDownCell*) [tableView dequeueReusableCellWithIdentifier:@"DropDownCell"];
if (cell == nil){
NSLog(@"New Cell Made");
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DropDownCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[DropDownCell class]])
{
cell = (DropDownCell *)currentObject;
break;
}
}
if (dropDown1Open) {
[cell setOpen];
}
[[cell textLabel] setText:dropDown1];
}
// Configure the cell.
return cell;
break;
}
default: {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
NSString *label = [NSString stringWithFormat:@"Option %ld", [indexPath row]];
[[cell textLabel] setText:label];
// Configure the cell.
return cell;
break;
}
}
break;
}
}
}
return cell;
}
はまってしまって、なかなか前に進めません。
回答の方をよろしくお願い致します。