2010-11-17 142 views
0

我需要有人来帮助我切换自定义单元格时选择使用didSelectRowAtIndexPath,所以想法是将自定义cell1设置为一个状态,当用户选择它会消失,并且cell2将淡入其中,显示该州的首府,但其他单元格将保持为除选定的单元格之外的单元格。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 2010-11-17 15:32:29

0

必须使用只有一个格,具有的倍数次(用α-一些视图设置为透明的,或隐藏)

当选择小区

,切换动画块

相关问题