Trying to remove Super ViewController but stuck in View? - iphone

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?

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.

Related

UIview doesn't load with viewdidappear

I have a tableview project which has a view, everything that I do in this view is controlled by "viewdidappear" method.
I added a new UIview which has "lines.h" and "lines.m" files.
I use this view to draw some lines and works god.
This extra view is located in to a scroll view because is to long to display in to iPhones screen.
The problem is that viewdidappear doesn't reload the uiview data, it only works with viewdidload.
I have to close the application and reopen it to get my data reload.
First, try adding this line at the end of viewDidAppear method:
[self.view setNeedsDisplay];
Or:
[_linesView setNeedsDisplay];
Second, Provide some more information. Post the code in viewDidLoad and viewDidAppear.
Try calling [self setNeedsDisplay] in the lines UIView class to cause the view to redraw itself.

UIview doesn't work property with viewdidappear [duplicate]

I have a tableview project which has a view, everything that I do in this view is controlled by "viewdidappear" method.
I added a new UIview which has "lines.h" and "lines.m" files.
I use this view to draw some lines and works god.
This extra view is located in to a scroll view because is to long to display in to iPhones screen.
The problem is that viewdidappear doesn't reload the uiview data, it only works with viewdidload.
I have to close the application and reopen it to get my data reload.
First, try adding this line at the end of viewDidAppear method:
[self.view setNeedsDisplay];
Or:
[_linesView setNeedsDisplay];
Second, Provide some more information. Post the code in viewDidLoad and viewDidAppear.
Try calling [self setNeedsDisplay] in the lines UIView class to cause the view to redraw itself.

troubles adding splash screen subviews to UIwindow

I have an app that has a login screen and splash screen. I want these screens to show up one after the other, and as such I have resulted to adding them as subviews to the app delegate's window property.
[window addSubview:mainViewController.view];
[window addSubview:loginViewController.view];
[window addSubview:splashScreenViewController.view];
The problem is that each subsequent subview that is added seems to appear in a weird manner(the orientation of the nib file is not obeyed). I know my nib files are not at fault, because if I only include one view, no matter which view it is, it shows up right. Furthermore, if I add the views as subviews to the main view controller's view(as opposed to app delegates) view, i dont get this issue. However, there is a 20px gap at the bottom of the screen because I guess UIWindow accounts for the status bar, and normal UIView's do not.
Does anyone have any idea what the problem might be? Is UIWindow doing something special? Am I not supposed to add several subviews to UIWindow? If anyone has tips regarding how to do splash screens, that would be much appreciated.
I suggest you use a UIView in the middle...
UIView view = [[UIView alloc] init];
[view addSubview:mainViewController.view];
[view addSubview:loginViewController.view];
[view addSubview:splashScreenViewController.view];
[window addSubview:view];
[view release];
After what if you what to animate as a splash screen, take a look at one of my post :
how to open a new uiview like a popup?
You should only have 1 view controller at a time.
You should use the -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController delegate function to check which tab was clicked. If it's your second view (which it should be if there are only 2 tabs) then call a custom method in your splashscreencontroller that pops up the modal. If that splash screen is only supposed to show once, make sure to set a flag afterwards to make sure it doesn't pop up again.
A TabBarController loads all the views before displaying them, so there's no lag when a user switches between tags.

How can I add a ViewController to scrollview

I have a scrollview I'm trying to add ViewControllers to from a nib file.
ViewController *controller=[[ViewController alloc] initWithNibName:#"ViewController" bundle:[NSBundle mainBundle]];
[scrollview addSubview:controller];
Scrollview is defined elsewhere.
Whenever I add other items like UIViews with simple colored backgrounds, that works fine. When I add the ViewController from the nib, the Viewdidload gets hit, the images load from the nib, but then the controller code stops there (No viewWillAppear etc). So I don't get any of the controller's processing.
This same controller works fine when pushed as a nav or tab controller. I'm sure I'm missing something in my educational process, but was hoping someone could help out so I can move on.
BTW: The ViewController above is a simple UIViewController.
I think your issue is that addSubview is expecting a UIView not a UIViewController - you probably get a warning when compiling ('may not respond to selector' or similar?). If so, don't just ignore those - in my experience, usually they are a problem in your code :-)
You could try something like
[scrollview addSubview:controller.view];
But this still won't get you the viewcontroller's processing ...you need to do that processing in the view controller that has the scrollview AFAIK. I would suggest trying to get a basic view with a scrollview working in IB first.
OK, seems a little off, but I added viewWillAppear to viewDidLoad, and that worked, but this doesn't seem the right way to do it, correct?

iPhone SDK: Advancing from one view to another using a button tap

I want to make a really simple iphone app: one screen with a single button... when the button is tapped a new screen appears. That's it. No animations, nothing,
I've tried endlessly to make the NavBar sample project do this... and it works but only if I use a UINavigationController with a table that I can tap etc. I've tried all the skeleton projects in XCode too.
I thought I was done when I did this:
[[self navigationController] presentModalViewController:myViewController animated:YES];
But I couldn't do it without the UINavigationController. I just want a simple example.
Thanks so much!
One way you could do this is to create a new UIView and then when the button is pressed add that new UIVIew as a subview, therefore making it what you see.
If you make the new view its own subclass of UIView you would do something like this.
LoginView *login = [[LoginView alloc] initWithFrame: rect];
[mainView addSubview: login];
[self presentModalViewController:myViewController animated:NO];
Will pop up a new view, no animations, nothing. To get rid of it, inside myViewController:
[self dismissModalViewControllerAnimated:NO];
Though I reccomend you use the nice sliding animations (change NO to YES.) And yes, you can stack them up. I think this is better than creating a new UIView, but I may be wrong.
The correct way to do this is set up your project with a UINavigationController. In your root view controller, add your button in the view controllers's view. Then in viewDidLoad, register for UIControlEventTouchUpInside events from you button. Then, in your event callback, call:
[self.navigationController pushViewController:[[[SecondViewControllerClass alloc] initWithNib:nibName bundle:nil] autorelease]];
What kdbdallas suggested will work, but you won't get the nice sliding effects, nor will the navigation bar automatically change and provide your users with a back button.