I have created an iPad app. In the middle of the app, under a button I have added a split view. After the button is clicked the split is shown successfully. But in the split view I want to add a button. When the button is tapped then I want to remove the split view and show another xib in whole screen. How can I do that?
First I had some questions,
if you able to add a Splitview on top of a viewcontroller with its button click?
In the above case do you get orientation in splitview controllers?
While I try to do I had this two problems.
Then What I do is, On a button click to show the splitview I called UIApplication Primary window, remove all current views in window and Add the new controllers view.
Do the Same as when need to go back.
See the following code,
- (void) displayControllerViewStack: (UIView *)view {
NSArray *subViews = [self.window subviews];
while ([subViews count] > 0 ) {
// Need to clear out the list, as only view at index 0 gets rotation notification.
[(UIView *)[subViews objectAtIndex:0] removeFromSuperview];
subViews = [self.window subviews];
}
[self.window addSubview: view];
}
thanks,
Naveen Shan
Related
I've got a UITableview that displays the search results of a UISearchController. They are inside of a Childviewcontroller.
I write the text on the textfield of the parentviewcontroller and it passes the text to the searchbar of the child view controller.
This all works fine.
But for some reason, when I am choosing a result in the child view controller's tableview, it is not very responsive.
After typing in the search text in the textfield (having the textfield as the firstResponder), most of the times I have to tap more than once to select a row.
(P.S. userInteraction is enabled, otherwise no touch would ever go through.)
Any idea why?
I have same problem, and my solution is:
- (void) displayContentController: (UIViewController*) content{
[content.view setFrame:recorderView.bounds];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:content];
childNavController.toolbarHidden = NO; // if you show toolbar
childNavController.view.frame = content.view.frame;
[self addChildViewController:childNavController];
[recorderView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];
}
content is my subViewController
Is this for Swift or for Objective-C? Also are you placing a UI Tap Gesture Recognizer on the views that you wish to be touchable?
Is there anyway to remove a view from the uiapplication window of a particular class?
I have a class called MainView that is the top header bar for the app on the main screen. I have a view that gets added after that where users can swipe up and down to different screens but on the screen where a user swipes up or down too the MainView bar at the top needs to be removed. How should I go about this? Should I try removing this MainView class from the UIApplication?
[yourSubview removeFromSuperview];
If your MainView instance is added directly to the window, you can get the array of the window's subviews. Then iterate over the subviews until you find a view that is type MainView and remove it from the window.
NSArray *subviews = [UIApplication sharedApplication].delegate.window.subviews;
for (UIView *view in subviews)
{
if ([view isKindOfClass:[MainView class]])
{
[view removeFromSuperview];
break;
}
}
I am practicing ios and I am trying to make simple real estate app, one viewcontroller, I put navigation bar and at the right sie of navigation bar I have button map
(I am trying to show all houses in area with basic data:street, price, long, lat... in tableview and just like marker on mapview).
I want that button to behave like toggle, to switch between table view and map view but in same controller. ( In android I could put one below other and just alternately set visibility to gone to one and visible to another).
How to alternately switch views in same controller (view need to be all over screen) ?
just assign the newView to oldOne
UIView *generalView=[UIView alloc]init];
[self.view addSubView:generalView];
when you want to show tableView ,then just assign
generalView=tableView;
and when you want map, then
generalView=mapView;
Are you using a storyboard? Why not just perform a segue on button tap?
- (void)myButtonMethod
{
//execute segue programmatically
[self performSegueWithIdentifier: #"MySegue" sender: self];
}
"MySegue" would be the segue identifier that is set in the storyboard between the two views.
Add two views tableview and maple to UIViewController's view.
It would be like:
-(void) viewDidLoad
{
[self.view addSubview:tableView];
[self.view addSubview:mapView];
}
On button click decide which view needs to be displayed:
-(void) onButtonClick:(UIButton *)sender
{
//If you want to display map..
[self.view bringSubviewToFront:mapView];
//If tableview needs to display
[self.view bringSubviewToFront:tableView];
}
Suppose i have a uiview in 1 screen and i want to view the same view in fullscreen mode on click of a button.
On click of a button the following function is called.
-(IBAction)fullScreen
{
FullScreenViewController *mv = [[FullScreenViewController alloc] init];
mv.fullview = minimizedView;
//minimizedView is a UIView already created with a specified frame
// fullview is a UIView decalred in FullScreenViewController
[[self navigationController] pushViewController:mv animated:YES];
}
In the FullScreenViewController.m the viewDidLoad function is as follows :
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:fullview];
}
On click of the fullscreen button, the view appears but on click of back button, the minimized view in the previous page dissapears.
Is it wrong to do this?
You dont need to use two views to implement this. In your code, your are navigating from one view to another view. You dont need to do that. Your minimizeView itself having a property "setFrame:" to increase and decrease its frame to resize of that subview in your current view itself. Learn how to resize the UIView.
I'm working on an iPad app in a split view controller where the app will remain in landscape the entire time. I would like the root view controller to remain a list and the detail view controller to swap out 4 different views controlled by a UISegmentedControl.
I'm following this post here UISegmentedControl Best Practice, however when I swap in my view controllers, they don't properly fit in the detailview controller, they are cut off as if they are trying to draw for ipad portrait orientation.
If I completely ignore the segmented control approach and have a detail view, the view size properly in the detail view, but once i try to swap them in with a segmented control is where I run into trouble.
Is there a way to tell the swapped in views to draw correctly?
Have you tried:
swappedInView.frame = detailController.view.bounds;
when you call
[detailedController.view addSubview:swappedInView];
?
Their contents need to have their resizing behaviors (most easily in xcode/IB) set appropriately.
I am using a UISegmentControl as well, but adding my views programmatically. I have my default view (segment 0) loaded first in the viewDidLoad of the rootController. Then based on which segment is pressed, I check if the view has been initialized, if not, initialize, then add it as a subview. Then remove the other view. I had a similar post on this on how to keep track of it that might help you out, and has the code from Beginning iPhone 4 Development book that I used for my own app. Here's the code snippet to get you started if you want to go this approach:
if (self.yellowViewController.view.superview == nil)
{
if (self.yellowViewController == nil)
{
YellowViewController *yellowController =
[[YellowViewController alloc] initWithNibName:#"YellowView"
bundle:nil];
self.yellowViewController = yellowController;
[yellowController release];
}
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0];
}
else
{
if (self.blueViewController == nil)
{
BlueViewController *blueController =
[[BlueViewController alloc] initWithNibName:#"BlueView"
bundle:nil];
self.blueViewController = blueController;
[blueController release];
}
[yellowViewController.view removeFromSuperview];
[self.view insertSubview:blueViewController.view atIndex:0];
}
In my own, I add as a subview, instead of inserting it behind the other views (they had a toolbar in the front in their example). So if say segment 3 was pressed, then I would check the other views if their superviews were present, remove that view, add my view. Hope that helps.