TabBar Simple Concept - Difficult Using

Discussion in 'iOS Programming' started by peacetrain67, Jul 14, 2009.

  1. peacetrain67 macrumors member

    Joined:
    Dec 20, 2007
    #1
    So I have started off developing my app (I am faily new to developing), and have set up a log in screen, webviews, etc., without many hitches, but I am stuck at a vital part of the application. After the beginning of the application, I have a button that sends the user to a new page (no kidding, right?), but at this new page I would like it to be based off a TabBar controller. I understand how to use the TabBar controller once I have it implemented, but don't know how to open to a TabBarController opposed to a view. I have played around and trailed-and-errored looking for a solution, but haven't had any full success. This seems like it should be a straight forward concept, but due to the fact that there arent any subclasses of TabBarControllers ready to be placed in the app, I am starting to think I am going to have to redevelop the whole application. So, my question: How can I make a new page open to a TabBarController instead of a view (in the middle of my app, not at the launch)?

    *And, if you want extra brownie points, i have two more questions: how can I have the user only log in once and then be always directed to a page with their log in keychain saved? The other: How can I make a UITextField become secure only after the user begins entering their own information (if I have password written in the UITextField, for example, and want it to be secure when they start typing)?

    Thanks in advanced for any help with these three questions.
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #2
    Look around Apple's apps that use a Tab Bar controller. I don't think you'll find any apps that use a Tab Bar Controller for only *part* of the app. The convention is to just create a Tab Bar Controller at the beginning of the app and go from there.

    I would create a "Login" tab, then just have the user directed to this tab at the launch of the app.
     
  3. amorya macrumors 6502

    Joined:
    Jun 17, 2007
    #3
    Or present the Login "page" as a modal view, so that it covers up the tab bar until it's dismissed.
     
  4. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #4
    the only problem with this, and the last response both will require recreating the whole application. I will go with the modalviewcontroller suggestion but, the latter 2 questions are equally important and i could *please* use answers for both/either of those answers. thanks already and thanks for coming answers
     
  5. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #5
    My novice side is showing: (As far as I understand->) I am having trouble with this because UITabBarControllers actually start with a window and in the app delegate tell it to load the TabBarController instead. How can I tell it to use a seperate window first but then be able to come back to the TabBarController (instead of the window) later on. I would prefer to do all this with a modalviewcontroller to keep the animation, but I could live with it for sure.:confused: Please help me here.
     
  6. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #6
    Don't.

    Rewrite the app with the Tab Bar Controller loaded from the start. Use a Modal View Controller like amorya said.

    You'll thank us later.
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    First look at that placeholder property of UITextField. This may do what you want.

    Second, the secureTextEntry property can be set at any time you like to make a text field secure or not secure.
     
  8. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #8
    I am planning on doing this, but am getting an error. In a few minutes I'll explain more if I can't get this kink worked out.

    *What would be the proper code to place a Class "LoginViewController" in the AppsDelegates
    "// Add the tab bar controller's current view as a subview of the window"? I am having trouble here consistently. The reason I am having trouble is because the way a UITabBarController applications work is by using this location to call the UITabBarController.
     
  9. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #9
    So I believe I got the coding [close to] correct, but I am getting a warning and the application quits unexpectedly. Here's my current code in the appname AppNameAppDelegate:

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    {
    LoginViewController *startapp = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:startapp];
    }

    The warning I get reads: warning:'AppNameAppDelegate' may not respond to '-presentModalViewController:' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
     
  10. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #10
    True Dat.

    presentModalViewController: is an instance method of UIViewController.

    So you either need to presentModalViewController in one of your view controllers or use your rootViewController or use your tabbarcontroller.
     
  11. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #11
    sorry, but can you elaborate or explain that a little more. i'm still grasping developing, so should i add a viewcontroller to the document or what? im tired and a novice so please cut me some slack.
    can i not load the first page as a modalviewcontroller like previously suggested? if i can't, simply explain to me another way to load the alternative page before the tabcontroller page...
     
  12. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #12
    Honestly, if you are having trouble understanding that warning, I would stop with what you are doing. Don't worry about Tab Bar Controllers, Modal View Controllers, or secure Text Fields. Just spend some time with Objective-C and some basic Cocoa Touch for a while. Pretty soon, View Controllers will seem a lot easier to understand.
     
  13. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #13
    instead of trolling can you answer the question? i had the majority of the app complete and then i was gonna start reading up more on objective-c, but at this point i feel like it's such a waste to just stop. really, a little time and a few of these answers and i should be finished; I know there are a lot of things to learn yet for me, but i'm trying to learn from trial and error, tips, and one of the best ways to learn is through experience, so could you actually help me through the experience instead of critiquing which method I'm learning. This way I'll get a basic grasp on what I will need to learn before jumping into reading materials and such that could start over my head. It's really hard to grasp some of that reading without ever playing around with it, and it's really annoying when people don't help but instead choose to question what i am doing.
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    How was that trolling? It may have been a tad harsh but it I think I kinda agree with the sentiment.

    Rather than us just giving you the answer, here's your opportunity to gain some experience through trial and error and playing around with it on your own. :D
     
  15. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #15
    I have figured out a lot of things by myself, but apparently I haven't qualified to ask for a question yet?

    I have figured it out to an extent, but the purpose of this is to have a log in screen and then go to a tabbarcontroller, and as of right now I'm still having trouble getting from the log in to the tabbarcontroller. I have looked through the hills for a way, but I know there are a lot much more experienced developers here that could easily just tell me a few steps to get this up and running. I actually had the app nearly completed but I accidently deleted it (stupid, I know, I overwrote it actually doing some trial and error, not realizing that was the one that whenever I started to grasp something, I actually implemented it into).
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    You have. Just a little unsure what exactly the question is that you're asking.

    So, you were successful in getting the login view presented modally? Then, in order to get on to the tab bar view, you will want to dismiss the modal view that is the login screen.
     
  17. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #17
    well, right now I don't have the modal view set up, I just have it set up to go to the normal MainWindow.xib. If you could, please tell me how I would get the login view to present modally. I know the location, obviously, but am having trouble coming up with the right code to load the login view modally and then dismissing it to another screen that isn't the default screen when the app launches (tabbarcontroller applications, when they launch, use the same location to call the tabbarcontroller as I would use to call the login view).
     
  18. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #18
    presentModalViewController:animated: is the instance method of UIViewController that you want to call. So, you need to call it on an instance of UIViewController. Hint: UITabBarController is a subclass of UIViewController.
     
  19. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #19
    I don't understand how it is possible to use a modalviewcontroller to open the application to a UIViewController if there isn't a UIViewController in the document (although obviously there is a UITabBarController, that is not what I want to call. I want to call a whole new class here, which always leaves me with an undeclared presentModalViewController, though. Currently, I have a similar code to what i started with:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {

    LoginViewController *startapp = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
    [presentModalViewController:startapp animated:YES];
    }

    but am receiving an error 'presentModalViewController undeclared.'

    Sorry about how slow I'm being right now, but I am very tired and exhausted from a lot of things (including this one nitch in my app), I really do appreciate the help and am sorry about being slow/quickly aggravated. I just want to call it a day with the modalviewcontroller succesfully called to open the app (and when excused leading to the tabbarcontroller). i feel like this is an easier concept then some stuff I have toyed around with it, but for some reason has been the biggest hassle.
     
  20. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #20
    If I am correct though, I can simply load the tabbarcontroller subview in the same location as the modalviewcontroller, with the modalviewcontroller coming after and when dismissed leading us to the tabbarcontroller. I can consider that minimal, but some, progress.
     
  21. mraheel macrumors regular

    Joined:
    Apr 18, 2009
    #21
    There are some design issues with how your going about it!
    And you gotto be careful what you call in appDidFinish..

    your probably adding a subview, your tabbarcontroller and your trying to present a modalview controller as well.

    where are u putting in your code? in appdelegate? in your mainViewController (This is the viewController of the first tab that shows up).

    I havent tried it, but I'd go about it this way,

    declare/subclass your modalViewCont in the MainViewController.h (first tab)
    ModalViewController *modalViewController.

    in MainViewController.m, under awakeFromNib or viewdidload... etc..(iniWithNIBName wont work in tab bar apps) call your modalView.

    [[self tabbarController] presentModalViewController:modalViewController animate:yes/no];

    Ofcourse, all this would actually depend on how u want your modalview to behave.
    All this would do is showup a vew, when the first tab controller is loaded which is the start!..


    And, this forum has got some great guys who're always helping out.. I learn the same way as you do. But I refrain from just talking about what this error means or what is the code!. Look for directions. and when u find one, u'll get the code from anywhere. I have a lot of questions in my head, like
    Is there a difference in loadingtime/performance when we link a tab to new vew.xib or keep all tab and their viewcontrollers in mainview.xib, in which case, theres only one xib!.

    But i dont ask that question(ahem) since I'll compile all my questions and throw them at once ;)
     
  22. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #22
    yes, exactly

    I wasn't aware you could declare a modalviewcontroller anywhere, haha. Should I declare my subclass for the modalview (the viewcontroller, not the tabbarcontroller view), or am i missing something big? I know I am asking some basic questions here, but learning through experience is most effective for me, and this is something I will probably use in every app I eventually make. the other problem with this, if i do declare the viewcontroller is that [[self tabBarController] would make whatever I type after it completely moot. One last thing, in the coding it's animated:YES/NO]. I feel close to finally getting this damn thing worked out (although now I'll have to transfer basically the whole application over that I had before deciding to add a tabBarController).
     
  23. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #23
    As I've hinted, UITabBarController is a subclass of UIViewController. So, yes, there is a UIViewController in your document.

    So, you need to call the presentModalViewController:animated: method on a UIViewController instance. So, more hinting:
    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
        
        // Add the tab bar controller's current view as a subview of the window
        [window addSubview:tabBarController.view];
    
        // Present the login view as a modal
        LoginViewController *startapp = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
        [instanceOfSomeClassThatIsASubclassOfUIViewController presentModalViewController:startapp animated:YES];
    
    }
    
    Just replace the 'instanceOfSomeClassThatIsASubclassOfUIViewController' with the name of the instance that I've been hinting about.

    P.S. Please enclose code snippets in [ CODE ][ /CODE ] tags (removing the spaces, of course). It's make it easier for the rest of us to read.
     
  24. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #24
    I think I just won the award for slowest person on the forums, but I can take consolation in the fact that I (if you count this as me) finally succeeded. I REALLY appreciate the help, and am now dealing with fact that at about 5 points I tested the same coding with tabBarController replaced by viewController. I don't know why I couldn't make the right connection there, but either way I really do appreciate the help. I now have to port over my log in (that does have much more then log in actually, with 5 different paths to choose including create account, view full site, log in, email us, and an information page - all fairly easy concepts). I probably will be in the next few days with another hitch (I am fearing UIPageControls already), but hopefully I can figure those out easier. Thanks again for the help guys, I got a better understanding of modals now.

    *And from now only I will use [ CODE ][ /CODE ]
     
  25. bdorpetzl macrumors regular

    bdorpetzl

    Joined:
    Jul 13, 2007
    Location:
    Port Washington, Wisconsin - Boats and Beer . . .
    #25
    @ The OP. If you are a paid dev, I would suggest looking over the NavBar app sample code provided by Apple if you plan on using a modal view controller as your login (that's what I would do at least. The sample code should give you a better understanding of the modal view controller and its use within a UINavigationContrtoller (another subclass of UIViewController). You can also look at the sample code for the app theElements for a UITabBarController example.

    No matter what, you need to have the UITabBarController as the rootViewController, it is the "most important" of the subclassed view controllers.
     

Share This Page