0

I am trying to make a Tab Bar application where one of the ViewController contains a UIToolbar with a UISegmentedController. The problem I have run into is setting up the UISegmentedController to switch between two views, for the views I am trying to switch between are subclasses of UIWebView and I would like to have them in separate files. (e.g. not just setting up the two views in "-viewDidLoad" of the ViewController.

The code of the method in the ViewController looks like:

- (IBAction)segmentedControlChanged
{   
switch (segmentedControl.selectedSegmentIndex)
    {case 0:
        [self.view addSubview:videosView];
        [imagesView removeFromSuperview];
        NSLog(@"1");
        break;
case 1:
        [self.view addSubview:imagesView];
        [videosView removeFromSuperview];
        NSLog(@"2");
        break;
default:
        break;
}

Where I have the videosView.h, videosView.m, imagesView.h, and imagesView.m imported in at the top of this document and set up as subclasses of UIWebView.

The errors I am getting seem to indicate that its not accepting imagesView or VideosView in the addSubview and also that removeFromSuperview is not a known class method.

Thanks in advance!

Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
David May
  • 17
  • 4

2 Answers2

0

Take a look at this pod: https://github.com/xmartlabs/XLMailBoxContainer. It makes the UI animation among the view controllers. These view controller can extend UITableViewController or any other view controller.

I hope this help you!

mtnBarreto
  • 282
  • 1
  • 3
  • 9
0

1- A UIViewController does not respond to removeFromSuperview, a UIView does

2- addSubview required a subclass of UIView to be passed to it, not a UIViewController

- (IBAction)segmentedControlChanged
{   
switch (segmentedControl.selectedSegmentIndex)
    {case 0:
        [self.view addSubview:videosView.view];
        [imagesView.view removeFromSuperview];
        NSLog(@"1");
        break;
case 1:
        [self.view addSubview:imagesView.view];
        [videosView.view removeFromSuperview];
        NSLog(@"2");
        break;
default:
        break;
}
aryaxt
  • 76,198
  • 92
  • 293
  • 442
  • thanks for the quick reply-- I just had to make a quick change to my post, because I believe my videosView and imagesView are actually subclasses of UIWebView. Would this change anything? – David May Dec 13 '11 at 03:41
  • A UIWebView inherits from UIView, so you should not be getting those warnings using your original code. Can you post the header files for those classes? – aryaxt Dec 13 '11 at 03:45
  • do I have to define `UIView *view` in the implementation of my imagesView and videosView files? – David May Dec 13 '11 at 03:47
  • If they are subclasses of UIWebView no – aryaxt Dec 13 '11 at 03:51
  • alright its still not perfect, for i realized that I actually had a different problem than this, so ill give you the checkmark and let you continue on. – David May Dec 13 '11 at 03:55