Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7859079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:45:56+00:00 2026-06-02T21:45:56+00:00

I currently encountering a problem with my iOS application. I am attempting to incorporate

  • 0

I currently encountering a problem with my iOS application.
I am attempting to incorporate a gradual login pattern, i.e.: the use can access some of the app without being required to login.

Required features are as follows:

  • At all times the user can view all navigation items that require login
  • When the user attempts to access an uiview(controller) that requires login, they will be prompted with a UIAlertView asking them to log in. (Preferably the UIAlertView will appear when the app recognised the initiated segue destination is restricted).

At first I used a subclass of UIViewController that, in the designated initialiser (initWithCoder), would check NSUserDefaults to see if the user was logged in. I then subclassed off of that. Limitations were as follows:

  • Couldn’t use other subclasses of UIViewController, namely UITableViewController
  • The UIAlertView came up after the view had appeared, which i am assuming would cause errors if the subclassed UIViewController assumed the user was logged in.

Question summary:
I would like to know how to conditionally prevent users from accessing certain UIView(Controller)s and subclasses of UIViewController, and when that happens present a UIAlertView.

Update 1
Could categories and/or protocols be a viable solution?

Update 2
CodaFi pointed out singletons as a great solution to manage the user’s state.

With that implemented I now need to figure out how to control the user’s access.
As I am using storyboards I feel that the most versatile implementation would be subclassing UIStoryboardSegue, and on the perform method check if the user is attempting to access an restricted UIViewController (perhaps restricted controllers have a protocol property that specifies the required status: logged in/out). However the pitfall here is that you cannot choose the class/subclass of a UIStoryboardSegue in the storyboard graphic editor. I am aware that I could do it programatically, however that seems tedious as i would have to add IBActions and like that to methods that perform segues, furthermore I don’t think that would work with the way elements such as navigationController and tabbarControllers behave.

Does anybody have a viable solution to restricting the user’s navigation?

Update 3
I’ve added an answer to this question, however I still deem it as unanswered because the answer I’ve written doesn’t take into account segues between navigation bar controllers. However it may help some people.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:45:57+00:00Added an answer on June 2, 2026 at 9:45 pm

    So, I’ve answered how to do this using custom segues.

    Now I understand my real problem was the mental disconnect with the tabbarcontrollerdelegate protocol.

    As a solution to preventing access to tabs I’ve made a class to handle said tab bar controller

    #import <Foundation/Foundation.h>
    
    @interface TabBarDelegate : NSObject<UITabBarControllerDelegate,UIAlertViewDelegate>{
        UITabBarController *cachedTabBarController;
    }
    
    @end
    
    #import "TabBarDelegate.h"
    
    @implementation TabBarDelegate
    
    -(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
        NSLog(@"%s",__FUNCTION__);
        NSLog(@"Pretending the user isnt logged in");
    
        if(true){
            NSString *message = [NSString stringWithFormat:@"You require an account to access %@",viewController.tabBarItem.title];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Account Required" message:message delegate:self cancelButtonTitle:@"Okay" otherButtonTitles: @"Login",@"Create Account",nil];
            [alert show];
            //Hold tabbarcontroller property for alert callback
            cachedTabBarController = tabBarController;
            return false;
        }
    
        return true;
    }
    
    -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
        if(cachedTabBarController){
            switch (buttonIndex) {
                case 1:
                    //Login
                    [cachedTabBarController performSegueWithIdentifier:@"tabBarToLogin" sender:cachedTabBarController];
                    break;
                case 2:
                    //Sign up
                    [cachedTabBarController performSegueWithIdentifier:@"tabBarToSignup" sender:cachedTabBarController];
                    break;
                default:
                    break;
            }
            //Release tab bar controller from memory
            cachedTabBarController = nil;
        }
    }
    
    @end
    

    Then i wired it up to my appDelegate in applicationDidFinishLaunching…

    //Hook up tab bar delegate
        mainTabController = (UITabBarController*)self.window.rootViewController;
        mainTabBarDelegate = [[TabBarDelegate alloc] init];
        mainTabController.delegate = mainTabBarDelegate;
    

    And Voila

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently porting an ObjC cocos2d game to cocos2d-x, but I'm encountering some problems
Currently developping a mobile webmail for my school, I am encountering the iPhone problem
I am currently encountering a problem while running a query which is calling a
I am encountering some very strange behaviour with a Flex 4.1 app I am
I'm currently working on a irc bot for a multi-lingual channel, and I'm encountering
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently I am debugging the signing of an Android app. And this would be
We're currently migrating our database back-end from Firebird to PostgreSQL. We use NHibernate as
I'm working on a web app that currently has a table-based layout. Ideally I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.