Retaining View between one view controller and UAModalPanel - iphone

I have two view controllers named as firstvc, secondvc. I have a subview in the firstvc, it looks like a form which has textfields. In firstvc there is a button to maximize that subview.
When I click on that, I am adding that subview to secondvc and I am presenting secondvc view in UAModalPanel. If I close that secondvc, firstvc should appear. My problem is that I was unable to retain that subview. It means when I close secondvc, firstvc subview is disappearing.
Can you suggest how to retain that subview between two view controllers?
-(IBAction)maximize:(id)sender
{
UIViewController *newview = [self.storyboard instantiateViewControllerWithIdentifier:#"second"];
[newview.view addSubview:subview];
UAModalPanel *modalpanelobject = [[UAModalPanel alloc]initWithFrame:self.view.bounds];
[modalpanelobject.contentView addSubview:newview.view];
[self.view addSubview:modalpanelobject];
[modalpanelobject showFromPoint:self.view.center];
}

I am the developer behind UAModalPanel. The panel does nothing to mess with the view hierarchy of views that are not added to the contentView so this problem probably would exist even without it. I would subclass the first controller's view and place a breakpoint in the dealloc and removeFromSuperview methods to see what is removing the view, when and why.

Look,
The concept is
There are three view you can consider.
Child View (ScrollView in your case)
Parent View 1 (GridCell)
Parent View 2 ('Maximized View)
What you are doing is when
1.You are maximizing the Child view
At that time you are taking the Child View from Grid Cell to Maximized View.
2.Now in reverse when you are closing the Maxized View.
Correct:At that time you SHOULD take the Child View from Maximized View to Grid Cell.
for doing that you can not find your Child View in Grid Cells.
Best Regards.

Related

Segue not working for dynamically added subview

I've got a storyboard with view A that is inside a navigation controller. I dynamically add subView B to view A. Subview B has a table view, and the table view cell has a seque (push) to a detail view. When I click on the cell, the prepareForSegue method is called, but the detail view is never displayed. If I switch the seque to a modal, then the detail view gets displayed inside view A, where subView B was.
What I want to happen is the detail view gets pushed onto the navigation controller and when the user hits back on the detail view it goes back to view A, with the subview B embedded.
Below is the code I use for adding the subview:
if(!self.homeViewController){
self.homeViewController = [self.storyboardinstantiateViewControllerWithIdentifier:#"HomeView"];
}
if(self.currentViewController != self.homeViewController)
{
[self.view insertSubview:self.homeViewController.view belowSubview:self.tabBar];
[self.currentViewController removeFromParentViewController];
}
self.currentViewController = self.homeViewController;
Without seeing your code (and storyboard) this may be hard to diagnose. I have found, however, that sometimes it's a chore to get segues to work properly with dynamically loaded content. In some cases I have found that using the pushViewController:animated: and popViewController:animated methods of the UINavigationController can be a better approach. You should be able to access the UINavigationController by through UIViewcontroller.navigationController.

Scroll of previous view in iphone App doesnt get disabled in the next view

i have two views say A & B. Both are the subclass of UIViewController class..View A is not a Table View but it is a scroll enabled view as it is more than the iphone dimensions 320*460. View B is not a scroll View. I am calling view B while clicking some button in View A like,
-(IBAction)bt:id(Sender)
{
B *mB=[[B alloc]initWithNib:#"B" bundle:nil];
[self.view addSubView:mB.view];
}
the problem is, As View A is larger, therefore when B is loaded over View A, even View A is partially visible in View B.please help me in overcome this problem??
The problem is you are adding view B to View A Subview and View A is in the scroll View so you need create a separate UIView Outlet and UIView in Interface Builder smallViewB the View A whatever size you need to display View B.
Then Add subview to View Outlet you created Above .
Please let me know if the problem persisting.
#interface ViewController A:UIViewController
#property(nonautomic,retain)IBOutlet UIView *smallViewB;
#implementation ViewController A
#synthesize smallViewB; //Make connection smallViewB in Interface Builder.
-(IBAction)bt:id(Sender)
{
B *mB=[[B alloc]initWithNib:#"B" bundle:nil];
[self.smallViewB addSubView:mB.view];
}
Before Adding view B to Main view remove the view A from its superview.
in .h take two objects
ViewA *aObject;
ViewB *bObject;
In View DidLoad create tow objects of View A and View B like this way
aObject=[[ViewA alloc]initWithNibName:#"ViewA" bundle:nil];
bObject=[[ViewB alloc]initWithNibName:#"ViewB" bundle:nil];
[self.view addSubView:aObject.view];
When You want to add View B add this code
[aObject.view removeFromSuperView];
[self.view addSubView:bObject.view];
Similarly IN Back Button action you can add code like
[bObject.view removeFromSuperView];
[self.view addSubView:aObject.view];
Try this code of snippets in your application I hope it will helps you. It wont lost your previous values of calss
Try adding this in you -(IBAction)bt:(id)Sender
ViewA.your_scroll_view.scrollEnabled=NO;
This might be what you wanted to do, if i understood it right.
Thanks for the suggestions but I have founda different solution to my problem.
When adding another view i.e. View B over Scroll View A, I reset the scroll view dimensions of A accordingly so that it is not visible. Also, when I press the Back button in View B, I again set the scroll View dimensions of View A to its previous value. Also, I made View A the delegate of View B since on pressing Back Button in B, I need to call a function which is defined in View A and is a part of View B protocol.

insert a xib as a subview, then add a subview from that xib over the parent view

I have some buttons on a view for navigation and when a user presses them my code inserts the appropriate new view page (xib) under the navigation buttons. Each new view page that I insert as a subview has some buttons that are supposed to pop up a new view over everything, including the navigation buttons. Here's one of my button actions
pg5 *pg5view = [[pg5 alloc] init]; //alloc and init UIViewController class for the view to be inserted.
[self.view insertSubview:pg5view.view atIndex:1]; //insert the subview under the menu but above the last subview displayed
[[[self.view subviews] objectAtIndex:0]removeFromSuperview]; //remove the last subview displayed
The issue here is that my new subview is inserted as a child of the navigation buttons view, so then when I use an action to addsubview from that viewcontroller, the view is added on top of that view controller, but not on top of the buttons because those are in the parent view. How can I solve this?
Thanks!
Ask the parent view to insert the subview, and code the parent so it knows how to manage swapping views around?

How to present a UIScrollView Modaly

I want to present a modal view with a UIscrollView as the content of the view. How would I do this?
As always, do a viewController and set it's view as the scroll view (in load view)
self.view = aScrollView;
and present it modally : (in your first viewController)
[self presentModalViewController:theViewController animated:YES];
Create a standard UIViewController, and give it a UIScrollView as its view member. Then use -[UIViewController presentModalViewController:animated:] on your current (visible) view controller. This will (by default) slide the new one in from the bottom.

What causes a UIViewController to become active?

I am sure this is an easy question, but one that has escaped me for some time now.
Say I have a UIViewController, either defined as a root in an XIB or on a stack. At some point in my code I want to replace it with another view controller. Just flat out replace it. How would I do that?
I have tried defining the controller and assigning, but not sure what actually makes it push on the screen with the absence of a navigation controller.
I think when you say that you want to replace the view controller, what you actually mean is that you want to replace the view. Bear in mind that view controllers aren't visible, but every view controller maps to a view, which can become visible by getting added as a subview of a visible view.
Your solution of replacing self.view with the new view controller's view may work in your particular case, but it's probably not the "correct" answer to your question. There are going to be cases where this solution won't work for you.
Let's say you have a simple view based application with no navigation controller and no tab bar controller. In your app delegate you construct an instance of YourFirstViewController, and you call [window addSubview:yourFirstController];. Your view hierarchy now consists of a UIWindow with a single subview -- the view for YourFirstViewController.
Now let's say the user presses a button on that view, which is handled by an IBAction defined in YourFirstViewController. You want to respond by "replacing" YourFirstViewController's view with a view associated with YourSecondViewController. I put "replacing" in quotes because we more commonly present a view by pushing its view controller onto a navigation stack, or calling presentModalViewController:animated: to present the view modally, but let's assume that you've rejected those options for some reason, and you actually do want to manually replace YourFirstViewController's view with YourSecondViewController's view.
This is a simple matter of manipulating the view hierarchy. You want to remove YourFirstViewController's view from its superview (the UIWindow in this case), and you want to add YourSecondViewController's view as a subview to replace it. Your action would therefore look something like this:
- (IBAction)replaceButtonClicked {
UIView *mySuperview = self.view.superview;
YourSecondViewController *secondController = [[YourSecondViewController alloc] init];
[mySuperview addSubview:secondController.view];
[self.view removeFromSuperview];
[secondController release];
}
When we use a methods like -pushViewController:animated: or -presentModalViewController, the receiving controller manipulates the view hierarchy for us. This may make it seem like we're looking at view controllers on the screen, but we're not. We're just looking at a big hierarchy of nested views going all the way up to a UIWindow at the top.
You can present a new view controller modally:
[self presentModalViewController:aViewController animated:YES];
This won't outright replace the current VC, but it will display a new view over the current view.