问题描述
我对设置表格视图单元格附件有点困惑.
I am confused a little bit about settings table view cell accessories.
我在我的表格中修复了两个部分
I have fixed two sections in my table
- 首页
- 办公室
我想要的是如下....
What I want is as follow....
- 当用户点击任何单元格时
- 单元格被选中&
- 我想设置选中(设置 uitableviewcell 附件类型 - 选中的单元格)
- 可用的视图单元附件类型无
我尝试了以下代码.但我发现 indexpath.row &indexpath.section 是只读属性.
I have tried following code. But I found that indexpath.row & indexpath.section is readonly properties.
// Override to support row selection in the table view. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tblProfileView deselectRowAtIndexPath:indexPath animated:YES]; int i,max; UITableViewCell *x; NSIndexPath *tt; for(i=0;i<[tblProfileView numberOfRowsInSection:0];i++) { tt.row=i; tt.section=0; x=[tblProfileView cellForRowAtIndexPath:]; [x setAccessoryType:UITableViewCellAccessoryNone]; } for(i=0;i<[tblProfileView numberOfRowsInSection:1];i++) { tt.row=i; tt.section=1; x=[tblProfileView cellForRowAtIndexPath:tt]; [x setAccessoryType:UITableViewCellAccessoryNone]; } x=[tblProfileView cellForRowAtIndexPath:indexPath]; [x setAccessoryType:UITableViewCellAccessoryCheckmark]; // Navigation logic may go here -- for example, create and push another view controller. // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; // [self.navigationController pushViewController:anotherViewController animated:YES]; // [anotherViewController release]; }
推荐答案
我会跟踪应该检查的数据并更改 tableView:didSelectRowAtIndexPath: 中的单元格:并更新检查的数据在 tableView:cellForRowAtIndexPath: 像这样:
I would keep track of the data that should be checked and change the cell in tableView:didSelectRowAtIndexPath: and update which data is checked in tableView:cellForRowAtIndexPath: like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // do usual stuff here including getting the cell // determine the data from the IndexPath.row if (data == self.checkedData) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // determine the selected data from the IndexPath.row if (data != self.checkedData) { self.checkedData = data; } [tableView reloadData]; }
这篇关于在 Tap & 上检查 UITableViewCell 附件类型设置其他未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2