iphone - CustomTabBarController 未响应委托(delegate)回调
<p><p>我使用 Martin 的 <a href="http://www.martinhoeller.net/2011/05/07/custom-tab-bars/" rel="noreferrer noopener nofollow">tutorial</a> 创建了一个自定义 <code>UITabBarController</code> .
我的子类 <code>FSTabBarController</code> 在 ViewController 之间切换,并且在我所见的范围内表现正常。</p>
<p>问题是,当我将 tabBarContoller 更改为我的子类时,它不会响应我的委托(delegate);</p>
<pre><code>- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
</code></pre>
<p>如果我将它改回 <code>UITabBarController</code> - 当我使用默认的 <code>UITabBarController</code> - 委托(delegate)会正常工作。</p>
<p>自定义子类使用以下函数来表示选项卡选择:</p>
<pre><code>- (void)_buttonClicked:(id)sender
{
self.selectedIndex = ;
;
}
</code></pre>
<p><strong>编辑:</strong></p>
<p>AppDelegate.h </p>
<pre><code>...
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) FSTabBarController *tabBarController;
</code></pre>
<p>AppDelegate.m</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
self.tabBarController = [ init];
self.tabBarController.viewControllers = ;
self.tabBarController.delegate = self;
...
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
// not called when FSTabBarController, called when UITabBarController !!
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>好的,从他的站点下载示例并进行测试。
是的,您需要从子类手动调用委托(delegate):</p>
<p>这就是你应该如何改变 buttonClicked 函数:</p>
<pre><code>- (void)_buttonClicked:(id)sender
{
self.selectedIndex = ;
if (self.delegate) {
;
}
;
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - CustomTabBarController 未响应委托(delegate)回调,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/12548699/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/12548699/
</a>
</p>
页:
[1]