我很困惑一些關於設置表格視圖單元格附件。UITableViewCell附件類型檢查點擊&設置其他未選中
我已經在我的表固定兩個部分
- 首頁
- 辦公室
我想是因爲遵循....
- 當用戶點擊任意的單元格
- 單元格被選中&
- 我想設置檢查(設置-checked抽頭細胞的UITableViewCell的附件類型)
- 以及所有其他細胞的附件類型現在應該設置爲
- uitable觀察室附件類型無
我試過下面的代碼。但是我發現indexpath.row & indexpath.section是隻讀屬性。
// 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];
}
由於您調用reloadData(根據您的數據可能很昂貴),因此這不是馬上行動。你可以簡單地:let cell = tableView.cellForRowAtIndexPath(indexPath) cell?.accessoryType =(yourTest)? .Checkmark:.None – Max 2016-03-21 12:44:32
你實際上不得不做幾乎兩者。直接按照Max指出的那樣進行更新,並在cellForRowAtIndexPath中配置單元格,或者在滾動列表時將單元格狀態混淆。 – marsbear 2016-08-18 18:49:58
哦,並實現didDeselectRowAtIndexPath以及你可以再次取消選中單元格。 – marsbear 2016-08-18 18:51:00