[英]ios Custom multiple selection for tableview
我有一張桌子,里面有三個部分。 每節有4行。 我希望每個部分有一個選擇,這使得整個表有3個選擇。 我正在嘗試使用以下功能進行此操作,這些功能可重置當前部分並設置新選擇。
- (void)selectOneRow:(int)row inSection:(int)section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
for(int i = 0; i < [[self.dataSource objectAtIndex:section] count]; ++i) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:section];
[self.table deselectRowAtIndexPath:ip animated:NO];
//[[self.table cellForRowAtIndexPath:ip] setHighlighted:NO];
}
[self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
//[[self.table cellForRowAtIndexPath:indexPath] setHighlighted:YES];
[self disableInteractionForRow:row inSection:section];
}
- (void)disableInteractionForRow:(int)row inSection:(int)section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
for(int i = 0; i < [[self.dataSource objectAtIndex:section] count]; ++i) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:section];
[[self.table cellForRowAtIndexPath:ip] setUserInteractionEnabled:YES];
}
[[self.table cellForRowAtIndexPath:indexPath] setUserInteractionEnabled:NO];
}
選擇第一部分的第一行的示例是:
[self selectOneRow:0 inSection:0];
這在第一次時效果很好,但是每次添加后記后,它都會關閉該行,使該部分為空白。 我怎樣才能解決這個問題? 還是我首先要解決所有這些錯誤? 感謝您的幫助。
**編輯添加圖像**
聽起來您正在嘗試使其變得過於復雜。 而不是將三個選項放在一個包含三個部分的表格視圖中,而是制作三個單獨的表格和三個單獨的視圖。
例如,轉到iPhone上的設置應用。 點擊“郵件,聯系人,日歷”,然后向下滾動到“郵件”部分標題下的“顯示”,“預覽”和“最小字體大小”選項。 對於這些設置中的每一個,將使用新的表視圖控制器推送新視圖,並且您只能選擇其中一個選項,然后返回。 這樣可以保持界面整潔,更不用說您的代碼了。
希望像這樣進行重組將對您更好。 我不知道我是否可以說您現在的做法是錯誤的,但這與Apple構建其應用程序的方式不一致。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.