在NavigationController中跳过登录视图控制器

时间:2017-01-22 05:06:03

标签: ios objective-c

我有一个标签栏,其中包含五个标签。我的应用程序不需要用户登录。如果用户注册或登录,则只允许使用某些功能。

如果用户已经注册/登录,我在连接到UserViewController的{​​{1}}中实现了以下逻辑。但是,在以下逻辑中,用户仍然可以在1-2秒内看到ViewController。

NavigationController

我想知道用户是否已经注册,我怎么能跳过UserViewController? 我希望tabbar单击直接打开-(void) viewWillAppear: (BOOL) animated { if(isRegistered) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UserProfileViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"UserProfileVewController"]; [self.navigationController pushViewController:vc animated:YES]; } } 而不是UserProfileVewController,这是登录/注册viewcontroller。

enter image description here

2 个答案:

答案 0 :(得分:1)

在项目的AppDelegate中,您可以检查用户是否已登录/注册,并依赖显示ViewControllers:

package game;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import java.util.ArrayList;
import javax.swing.*;

public class Game {

public final static int WIDTH = 1920, HEIGHT = 1080;

private String gameName = "Tutorial Game";

private Canvas game = new Canvas();

private Input input;

private ArrayList<Updatable> updatables = new ArrayList<>();
private ArrayList<Renderable> renderables = new ArrayList<>();

// Helper methods for update/render Arrays
public void addUpdatable(Updatable u) {
    updatables.add(u);
}

public void removeUpdatable(Updatable u) {
    updatables.remove(u);
}

public void addRenderable(Renderable r) {
    renderables.add(r);
}

public void removeRenderable(Renderable r) {
    renderables.remove(r);
}

public void start() {
    // Initialize windows
    Dimension gameSize = new Dimension(Game.WIDTH, Game.HEIGHT);
    JFrame gameWindow = new JFrame(gameName);
    gameWindow.setDefaultCloseOperation(3);
    gameWindow.setSize(gameSize);
    gameWindow.setResizable(false);
    gameWindow.setLocationRelativeTo(null);
    gameWindow.add(game);
    game.setSize(gameSize);
    game.setMinimumSize(gameSize);
    game.setMaximumSize(gameSize);
    game.setPreferredSize(gameSize);
    gameWindow.setVisible(true);

    // Initialize Input
    input = new Input();
    game.addKeyListener(input);

    // Game loop
    final int TICKS_PER_SECOND = 60;
    final int TIME_PER_TICK = 1000 / TICKS_PER_SECOND;
    final int MAX_FRAMESKIPS = 5;

    long nextGameTick = System.currentTimeMillis();
    int loops;
    float interpolation;

    long timeAtLastFPSCheck = 0;
    int ticks = 0;

    boolean running = true;
    while(running) {
        // Updating
        loops = 0;

        while(System.currentTimeMillis() > nextGameTick && loops < MAX_FRAMESKIPS) {
            update();
            ticks++;

            nextGameTick += TIME_PER_TICK;
            loops++;
        }

        // Rendering
        interpolation = (float) (System.currentTimeMillis() + TIME_PER_TICK - nextGameTick)
                      / (float) TIME_PER_TICK;
        render(interpolation);

        // FPS Check
        if(System.currentTimeMillis() - timeAtLastFPSCheck >= 1000) {
            System.out.println("FPS: " + ticks);
            gameWindow.setTitle(gameName + " - FPS: " + ticks);
            ticks = 0;
            timeAtLastFPSCheck = System.currentTimeMillis();
        }
    }                
}

private void update() {
    for(Updatable u : updatables) {
        u.update(input);
    }
}

private void render(float interpolation) {
    BufferStrategy b = game.getBufferStrategy();
    if(b == null) {
        game.createBufferStrategy(2);
        return;
    }

    Graphics2D g = (Graphics2D) b.getDrawGraphics();
    g.clearRect(0, 0, game.getWidth(), game.getHeight());
    for(Renderable r : renderables) {
        r.render(g, interpolation);
    }

    g.dispose();
    b.show();        
}
}

答案 1 :(得分:0)

您可以尝试让您的应用委托代表(或您真正想要的任何人)符合UITabBarControllerDelegate并实施- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController。在那里你可能能够对视图控制器进行必要的检查/调整。