我創建了一個自定義TablePickerViewController這是的子類UITableViewController。我使用這個類來顯示一個自定義類型的對象列表TablePickerItem。如何生成通用表格視圖控制器?
我使用TablePickerViewController多次在我的iOS應用程序,以顯示不同類型的列表,其中用戶必須選擇一個項目 - 然後另一個視圖控制器MainViewController應該在此選擇反應,並做一些事情。
我創造了這個協議,並在TablePickerViewController創建一個代表屬性:
@protocol TablePickerViewControllerDelegate <NSObject>
- (void)tablePickerViewController:(TablePickerViewController *)controller
didSelectItem:(TablePickerItem*)item;
@end
當我安裝一個新的TablePickerViewController在MainViewController它也被設置爲代理 - 比將在用戶點擊表格視圖中的單元時通知。
的問題是,我MainViewController將設置多個TablePickerViewController不同的數據(TablePickerItem)。我應該如何設置我的MainViewController來處理這些多重TablePickerViewController?來自它們每個的事件將導致調用我的MainViewController中的相同協議方法。
此外,我需要獲取TablePickerItem表示的元素,因爲我需要知道元素ID在tablePickerViewController:didSelectItem
方法中的作用。我是否應該通過向TablePickerItem添加類似@property (nonatomic) id element
的東西來處理此問題,並將原始對象設置爲此屬性,然後創建它?
也許有人可以給我一個關於如何創建一個通用表視圖控制器的例子,如果我的解決方案似乎以錯誤的方式完成。
你能分享這門課嗎?我有同樣的需要,如果可以發送到[email protected] – Nepster 2014-09-24 10:04:25