如果用戶點擊它,我想更改UITableView
的部分索引的顏色。如果用戶點擊UITableView部分,是否有可能收到通知?索引
我可以設置sectionIndexColor
和sectionIndexTrackingBackgroundColor
在初始化的tableview和任何其他國家,但我發現沒有方法來改變點擊索引顏色。
更新:
我的意思是在更大的tableviews A-Z側欄。這裏有一些圖像(見在圖像2灰色條)
未選中狀態
:選定狀態:
如果用戶點擊它,我想更改UITableView
的部分索引的顏色。如果用戶點擊UITableView部分,是否有可能收到通知?索引
我可以設置sectionIndexColor
和sectionIndexTrackingBackgroundColor
在初始化的tableview和任何其他國家,但我發現沒有方法來改變點擊索引顏色。
更新:
我的意思是在更大的tableviews A-Z側欄。這裏有一些圖像(見在圖像2灰色條)
未選中狀態
:選定狀態:
我只有一個相當髒的解決方案,因爲蘋果不支持公共api。我的實現工作很好,如果將來發生一些API變化(不再會崩潰),它不會崩潰。我將UITableView
繼承並將其自己的回調添加到sectionIndex視圖中,作爲子視圖添加到表中。
@interface MyTableView : UITableView
@end
@implementation MyTableView
- (void)selectionStarted {
[self setSectionIndexColor:[UIColor greenColor]];
}
- (void)selectionStoped {
[self setSectionIndexColor:[UIColor redColor]];
}
- (void)addSubview:(UIView *)view {
[super addSubview:view];
if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewIndex"] && [view isKindOfClass:[UIControl class]]) {
UIControl *cont = (UIControl *)view;
[cont addTarget:self action:@selector(selectionStarted) forControlEvents:UIControlEventTouchDown];
[cont addTarget:self action:@selector(selectionStoped) forControlEvents:UIControlEventTouchUpInside];
[cont addTarget:self action:@selector(selectionStoped) forControlEvents:UIControlEventTouchUpOutside];
[cont addTarget:self action:@selector(selectionStoped) forControlEvents:UIControlEventTouchCancel];
}
}
@end
不錯的解決方案,但我不能冒險,應用程序被拒絕使用私人API(雖然只是比較名稱)。 – AlexVogel
你不打電話給任何私人API,所以我不認爲蘋果會拒絕它。 –
使用UITableView
代表
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
然後修改所需要部分,你有indexPath。
最簡單的方法 - 只保留indexPath作爲屬性並重新加載tableView
,然後在viewForHeaderInSection
中,您應該比較indexPath並設置所需的顏色。
您的意思是選中的單元格顏色更改...?或者選擇了部分顏色更改? –
是否要更改整個索引或選定項目的顏色? –
@Jonathan Cichon:只有整個索引。在未選擇狀態下,它應該有深色,並且在選定狀態下顏色較淺。 – AlexVogel