我有一個的UITabBarController,我已經建立了委託方法didSelectViewController
,因爲我感興趣的是被選中的選項卡的索引。didSelectViewController沒有得到調用時在「更多」部分
然而,我注意到,didSelectViewController
方法不會被調用,當用戶是「其他」一節中(當有更多的標籤,無法在使用TabBar顯示):
有沒有辦法讓我得到通知用戶從表中選擇的項目是被自動創建的?
我有一個的UITabBarController,我已經建立了委託方法didSelectViewController
,因爲我感興趣的是被選中的選項卡的索引。didSelectViewController沒有得到調用時在「更多」部分
然而,我注意到,didSelectViewController
方法不會被調用,當用戶是「其他」一節中(當有更多的標籤,無法在使用TabBar顯示):
有沒有辦法讓我得到通知用戶從表中選擇的項目是被自動創建的?
我發現我需要什麼this question。
基本上你設置一個UITabBarControllerDelegate
和對於被更多標籤內顯示的導航控制器UINavigationControllerDelegate
。之後,您會檢測用戶是否觸摸了其中一個可見選項卡或「更多」選項卡。
編輯
此外,直接操作是「更多」導航控制器中是可見的表,你可以建立一個「人在中間人」表視圖的委託,截獲的通話原來的代表。從內部didSelectViewController
見下文代碼:
if (viewController == tabBarController.moreNavigationController && tabBarController.moreNavigationController.delegate == nil) {
// here we replace the "More" tab table delegate with our own implementation
// this allows us to replace viewControllers seamlessly
UITableView *view = (UITableView *)self.tabBarController.moreNavigationController.topViewController.view;
self.originalDelegate = view.delegate;
view.delegate = self;
}
之後,你可以自由地做任何你喜歡的委託方法裏面,只要您撥打的其他代表同樣的方法(其實我檢查哪些方法原代表響應,並且被實現的唯一委託方法是didSelectRow:forIndexPath:
)。看到下面的例子:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// this is the delegate for the "More" tab table
// it intercepts any touches and replaces the selected view controller if needed
// then, it calls the original delegate to preserve the behavior of the "More" tab
// do whatever here
// and call the original delegate afterwards
[self.originalDelegate tableView: tableView didSelectRowAtIndexPath: indexPath];
}
您是否嘗試過的NSLog既授人以看它是否有什麼不同?看起來是一樣的。 – 2011-12-23 03:39:14
我試圖找出這一個了。我能得到儘可能知道,當他們點擊更多,但看到他們從更多的tableviewcontroller選擇哪個瀏覽器需要使用非公開的API調用。 – 2011-04-27 13:43:21
@Greg,看到我的答案。 – Shade 2011-04-27 14:09:59