Iphone TableView和自定义单元格
当使用Iphone TableView和自定义单元格,iphone,tableview,cells,Iphone,Tableview,Cells,当使用didselectrowatinexpath选择时,我需要有人帮助我切换自定义单元格,因此,我们的想法是将自定义的cell1设置为一种状态,当用户选择它时,该状态将消失,cell2将淡入显示该状态的首都,但除已选择的单元格外,其他单元格将保留为cell1(或状态) 必须仅使用一个单元格,并具有多个视图(某些视图的alpha设置为透明或隐藏) 选择单元格后,在动画块内切换视图这就是我要做的 tableView.h: #import <UIKit/UIKit.h> @interfa
didselectrowatinexpath
选择时,我需要有人帮助我切换自定义单元格,因此,我们的想法是将自定义的cell1
设置为一种状态,当用户选择它时,该状态将消失,cell2
将淡入显示该状态的首都,但除已选择的单元格外,其他单元格将保留为cell1(或状态) 必须仅使用一个单元格,并具有多个视图(某些视图的alpha设置为透明或隐藏)
选择单元格后,在动画块内切换视图这就是我要做的 tableView.h:
#import <UIKit/UIKit.h>
@interface tableView : UITableViewController {
NSMutableArray *tableArray;
}
- (void)changeTitleAtIndexPath:(NSIndexPath *)indexPath;
@end
更改:
- (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];
}
加:
谢谢JNK,这正是我想要的,太棒了。
- (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]];
}