views:

42

answers:

1

Hello all,

I have 3 ViewControllers 1.Main 2.Gallery 3.Text. What my problem is that i have the GalleryViewController using an External UIView with the name GalleryItemView. So once the view controller calls this inside the UIView i have a button that changes the subview so what i do is use the [super addSubView:newView]; eveything works out great but when i return to the GalleryViewController my app crashes so im guessing im doing this wrong. also what i notice is that once i change Views from pressing the button inside the GalleryViewController takes me to the menu and when i do a swipe gesture it scrolls horizontal and i do have a scrollview in the GalleryViewController Class so maybe what im doing is adding a subview to the ScrollView anyone know how i can fix this?

+1  A: 

For starters:

[super addSubView:newView];

is pretty much incorrect.

Adding a view to a viewcontroller, you want to do

[self.view addSubview:galleryItemView];  
[self.view bringSubviewToFront:galleryItemView]; 

If you believe you have added it properly, you could do the following to verify it:

if ([galleryItemView.superview isKindOfClass:[UIScrollView class]]){
  NSLog(@"galleryItemView's parent is a scrollview"); 
}

Please post the crash if you still have problems.

David Sowsy
hello david thanks for your answer i haven't tried it; but i will when i get home. I want to make a note at, where i use [super addSubView:newView]; is on the UIView itself so this stops me from using [self.view addSubview:galleryItemView]; i get a compiler error saying self.view is not in union. the button to change views is on the UIView
Silent