2010-11-17 2 views
0

Мне нужно, чтобы кто-то помог мне при переключении пользовательских ячеек при выборе с помощью didSelectRowAtIndexPath, так что идея состоит в том, чтобы пользовательский cell1 был установлен как состояние, и когда пользователь его выбирает, это исчезнет и cell2 будет исчезать, в котором отображается столица этого состояния, но другие ячейки будут оставаться как cell1 (или состояния), кроме той, которая была выбрана.TableView и пользовательские ячейки

ответ

1

Это как Я хотел бы сделать это ...

tableView.h:

#import <UIKit/UIKit.h> 
@interface tableView : UITableViewController { 
    NSMutableArray *tableArray; 
} 

- (void)changeTitleAtIndexPath:(NSIndexPath *)indexPath; 

@end 

tableview.m (добавить эти методы):

в - (пустоте) viewDidLoad добавить:

tableArray = [[NSMutableArray alloc] init]; 
    [tableArray addObject:[NSMutableArray arrayWithObjects:[NSNumber numberWithBool:NO],@"City1",@"Capital1",nil]]; 
    [tableArray addObject:[NSMutableArray arrayWithObjects:[NSNumber numberWithBool:NO],@"City2",@"Capital2",nil]]; 
    [tableArray addObject:[NSMutableArray arrayWithObjects:[NSNumber numberWithBool:NO],@"City3",@"Capital3",nil]]; 
    [tableArray addObject:[NSMutableArray arrayWithObjects:[NSNumber numberWithBool:NO],@"City4",@"Capital4",nil]]; 

изменение:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if (![[[tableArray objectAtIndex:indexPath.row] objectAtIndex:0] boolValue]) { 
     cell.textLabel.text = [[tableArray objectAtIndex:indexPath.row] objectAtIndex:1]; 
    }else { 
     cell.textLabel.text = [[tableArray objectAtIndex:indexPath.row] objectAtIndex:2]; 
    } 




    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    [self changeTitleAtIndexPath:indexPath]; 
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop]; 
} 

добавить:

- (void)changeTitleAtIndexPath:(NSIndexPath *)indexPath{ 
    BOOL newBool = ![[[tableArray objectAtIndex:indexPath.row] objectAtIndex:0] boolValue]; 
    [[tableArray objectAtIndex:indexPath.row] replaceObjectAtIndex:0 withObject:[NSNumber numberWithBool:newBool]]; 
} 
+0

благодаря JNK, это именно то, что я искал, это здорово , – tosi

0

вы должны использовать только одну ячейку, с видом на кратные (некоторые точки зрения с альфа набор прозрачным или скрыть)

при выборе ячейки, переключите точку внутри блока анимации

Смежные вопросы