Previous 1 2 Next 29 Replies Latest reply: Jul 15, 2013 7:52 AM by CDACWimcNilesh Go to original post
  • PalNor Level 1 Level 1 (0 points)
    Hello Guyz... I know this thread is quite old but iam really having headache trying to solve my problem. I have an application where when the application runs u come to a menue of a social networking application. however, i made a button to make a flip to another view. I wanted that view to have the control managing the UITabBar and thats why I added the UITabBar on the top of that Specific View. that view is called (SecondViewController) and i declared the UITabBar, and a two view Controllers (ActivityViewControllers, MapViewController). All i wanted to show is a view for each of the tabs built on the SecondViewController. I followed this thread step by step and i get a bunch of errors

    error: expected expression before 'SecondViewController'
    error: expected ':' before '.' token
    confused by earlier errors, bailing out




    - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    NSLog(@"didSelectItem: %d", item.tag);
    }




    - (void)activateTab:(int)index {
    switch (index) {
    case 1:
    if (SecondViewController.ActivityViewController == nil) {
    self.ActivityViewController =
    [[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil];
    }
    [self.view insertSubview:ActivityViewController.view belowSubview:rootTabBar];
    if (SecondViewController.ActivityViewController != nil)
    [SecondViewController.view removeFromSuperview];
    SecondViewController = ActivityViewController;
    break;
    case 2:
    if (WebViewController == nil) {
    self.WebViewController =
    [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
    }
    [self.view insertSubview:WebViewController.view belowSubview:rootTabBar];
    if (SecondViewController != nil)
    [SecondViewController.view removeFromSuperview];
    SecondViewController = WebViewController;
    break;
    default:
    break;
    }
    }





    - (void)viewDidLoad {
    [super viewDidLoad];
    [rootTabBar setSelectedItem:[rootTabBar.items objectAtIndex:0]];
    [self activateTab:1];



    Any Help Would be really appreciated...
  • RayNewbie Level 5 Level 5 (6,810 points)
    Hi PalNor, and welcome to the Dev Forum!

    I'm having some difficulty following your code because I can't tell which identifiers refer to a class, and which refer to an object of that class. I would recommend making sure your identifiers follow the Obj-C convention of capitalizing the first letter of a class name, and beginning the identifier of an object with a lower case letter. For example:

    @interface SecondViewController : UIViewController <UITabBarDelegate> {
    // upper case // lower case
    ActivityViewController *activityViewController;
    WebViewController *webViewController;
    UIViewController *currentViewController;
    UITabBar *myTabBar;
    }
    @property (nonatomic, retain) ActivityViewController *activityViewController;
    @property (nonatomic, retain) WebViewController *webViewController;
    @property (nonatomic, assign) UIViewController *currentViewController;
    @property (nonatomic, retain) IBOutlet UITabBar *myTabBar; // <-- connect to the tab bar in IB
    @end

    There are also several lines that don't make any sense. E.g.:

    if (SecondViewController.ActivityViewController == nil) // ...

    If the above is inside the @implementation of SecondViewController, you would refer to the activityViewController instance variable as 'self.activityViewController' (assuming the identifier of that ivar starts with a lower case letter as shown in the @interface example). So I would expect that line to look like either of the following:

    if (self.activityViewController == nil) // ...
    // or:
    if (activityViewController == nil) // ...

    Most of the errors I see at first glance seem to be related to some confusion over the difference between a class and an instance of a class. There also seems to be some confusion over the view hierarchy. These are fundamental problems that will cause your program to fail regardless of how you're switching views. So if we can assist you further, I'd recommend starting your own thread. In that case, please include SecondViewController.h, as well as another copy of SecondViewController.m which is properly formatted.

    To format your code please refer to the announcement which is the first topic of the forum. You can see how your post will appear by clicking on the Preview tab above the Reply editor panel.

    - Ray
  • dennylee60 Level 1 Level 1 (0 points)
    Thank you so much for your code. It saved my life!
  • ChrisNaum Level 1 Level 1 (0 points)
    I just got a question : the solution proposed in the testtab_raynewbie doesn't work properly in fact : you cant remark that everything goes well as long as you don't click on the same tab twice (or more), in which case the second (and all others) nib loaded is the nib "implementing" the tabbar, and not the nib designing the tab. So that in fact the proposed solution is not a solution. And can we slightly modify this to make it work properly ? Thx
  • ChrisNaum Level 1 Level 1 (0 points)
    I just got a question : the solution proposed in the testtab_raynewbie doesn't work properly in fact : you cant remark that everything goes well as long as you don't click on the same tab twice (or more), in which case the second (and all others) nib loaded is the nib "implementing" the tabbar, and not the nib designing the tab. So that in fact the proposed solution is not a solution. And can we slightly modify this to make it work properly ? Thx
  • Hussain123 Level 1 Level 1 (0 points)
    like to adjust the uiwebview content as we zoom the content(text) needs to resize
  • tuckermax72 Level 1 Level 1 (0 points)
    Thank you so much for this code! but I am having one simple problem I just cannot figure out.
    I do not know how to return to my original view after visiting the tab bar view. I have tried to use the following code in my tab's view controllers but I can't get it to work.

    -(IBAction) toHome{
    [self dismissModalViewControllerAnimated:YES];

    }

    -(IBAction) toHome{
    testtabViewController *screen = [[testtabViewController alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:screen animated:YES];
    [screen release];
    }


    This is usually what I use to navigate nib files but the first code doesn't have any effect at all, and the second code returns to the main screen while remaining within the tab bar. How can I fix this?
    -Thanks
  • BjornSt Level 1 Level 1 (0 points)
    Hi Dev Forum!

    I tried the code from the solution and i also get the views mixed up. Its like it doesn't clear the screen at all. I know this is a pretty old thread but I really need to be able to mix tab navigation in a view based project I'm working on and i can't find much usable info out on the web about this. So if anyone has a way to fix this solution so it works or if anyone know of a better way to add a working tab bar to a view based application i would be very grateful!

    Best Regards

    Bjorn S
  • Slaaphoofd Level 1 Level 1 (0 points)

    I have the same problem, when returning to the main view the tabbar stays at the bottom.

    I tried everything but just cant seem to fix it....

     

    See also http://stackoverflow.com/questions/5978782/how-to-hide-a-tab-bar-in-a-view-based -tab-bar-application

     

    Anyone a solution?

  • mattgolding Level 1 Level 1 (0 points)

    I have used this solution and ran into a problem with the view loading below my tabBar but on top of the naviagation toolbar at the top of the screen.  This was fixed by modifying your code to read

     

    [self.view insertSubview:tab1ViewController.view belowSubview:_toolbar];
    

     

    However I have now run into problems with rotation of the device.  I am trying to add the tabBar into the details view of a splitViewController.  Like I said everything seems to be good except the rotation.

     

    I have created a new question at the following if anyone has a solution?

     

    https://discussions.apple.com/thread/3660615

     

    Message was edited by: mattgolding Put the code inside a code block

  • Dudelstein Level 1 Level 1 (0 points)

    How do you use the method outlined in page 1 to add a badge to a tab?

     

    [[self navigationController] tabBarItem].badgeValue = @"3";

     

    Something like that?

  • just.do.it Level 3 Level 3 (850 points)

    Hi,

     

    this should do it if [self navigationcontroller] is one of the UITabBarController controlled controllers. :-)

     

    Dirk

  • Dudelstein Level 1 Level 1 (0 points)

    No it didn't seem to work.

     

    The tabbar item doesn't get the badge.

     

    I also tried this in the viewdidload

     

    UITabBarItem *tbi=(UITabBarItem *)[_tabBarController.tabBar.items objectAtIndex:1];

    tbi.badgeValue="2";

     

    No syntax error, but just doesn't work. I am using the method outlined in page 1 to add a tab bar.

     

    in my .h file.

    @interface mycontroller: UIViewController <UITabBarDelegate>

    {

    ..define lots of stuff

    }

  • CDACWimcNilesh Level 1 Level 1 (0 points)

    Thanks RayNewbieand MUsman for this post.It helped me a lot.I am just a newbee in ios.So thanks a lot.

    Happy Coding..............

  • CDACWimcNilesh Level 1 Level 1 (0 points)

    Thanks Ray for your kind work.........I was really happy after getting the output.

    Do continue your good work for begineers like me.........

Previous 1 2 Next