0

我需要有人在选择使用时帮助我切换自定义单元格didSelectRowAtIndexPath,所以我的想法是将自定义cell1设置为一个状态,当用户选择它时,它会消失并cell2淡入淡出,其中显示该州的首都但其他单元格将保留为 cell1 (或状态),除了被选中的那个。

4

2 回答 2

1

我就是这样做的...

表视图.h:

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

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

@end

tableview.m(添加这些方法):

在 -(void)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]];
}
于 2010-11-17T12:55:16.840 回答
0

您必须仅使用一个单元格,并具有多个视图(某些 alpha 设置为透明或隐藏的视图)

选择单元格时,切换动画块内的视图

于 2010-11-17T12:12:05.083 回答