ios - 更改 Storyboard 后未调用 Tabbar 委托(delegate)方法
<p><p>我在登录 Storyboard 中有 <strong>login</strong> 和 <strong>signup</strong>ViewController ,而不是在主 Storyboard 中。 </p>
<p>一旦注册或登录成功,然后我将登录 Storyboard更改为 Main。以下代码有效,但是当我选择任何选项卡时,它不会调用 <strong>AppDelegate</strong></p> 中的选项卡委托(delegate)方法
<p>但是,如果用户已经成功注册或登录,则它会调用以下标签栏委托(delegate)方法。</p>
<p><strong>LoginViewController.m</strong></p>
<pre><code>if(isLoginSuccess)
{
UIStoryboard *mainStoryboard = ;
CustomTabBarViewController *tbc = ;
tbc.selectedIndex = 2;
;
}
</code></pre>
<p><strong>AppDeletage.m</strong></p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CustomTabBarViewController *tabBarController = (CustomTabBarViewController *)self.window.rootViewController;
tabBarController.delegate = self;
return YES;
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 2) {
if(!)
{
UIStoryboard *loginStoryboard = ;
UIViewController *vc = ;
;
}
else
{
tabBarController.selectedIndex = 2;
}
}
}
</code></pre>
<p><strong>更新:</strong></p>
<p>AppDelegate 没有被调用,但我想知道为什么以下代码在用户注销后没有在 AppDelegate 中打开 Loginstoryboard。</p>
<pre><code>#define ROOTVIEW [[ keyWindow] rootViewController]
UIStoryboard *mainStoryboard = ;
UIViewController *vc = ;
;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>请在下面找到代码。</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *main = ;
UITabBarController *tabController = ;
tabController.delegate = self;
return YES;
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"Selected Index - %lu",(unsigned long)tabBarController.selectedIndex);
}
</code></pre>
<p>关于ViewController的按钮点击方法,</p>
<pre><code>- (IBAction)btnLoginTapped:(id)sender {
UIStoryboard *main = ;
UITabBarController *tabController = ;
tabController.selectedIndex = 1;
;
}
</code></pre>
<p>然后在<strong>Main.storyboard</strong>上,将<strong>Object</strong>从<strong>Object Library</strong>拖到<strong>First Responder</strong>下面标签栏 Controller 场景,将<strong>对象类设置为AppDelegate</strong>,然后右键单击标签栏 Controller 并<strong>将代理设置为该对象类</strong>,如下图所示。</p>
<p> <a href="/image/Go9mB.png" rel="noreferrer noopener nofollow"><img src="/image/Go9mB.png" alt="enter image description here"/></a> </p>
<p>让我知道它是否有效,我已准备好帮助解决问题。</p></p>
<p style="font-size: 20px;">关于ios - 更改 Storyboard 后未调用 Tabbar 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48981920/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48981920/
</a>
</p>
页:
[1]