Set a UIPickerView to bottom of UITableview regardless of scroll position - objective-c

I'd like to present a UIPickerView snapped to the bottom of a UITableView regardless of where it is scrolled.
Currently I have a UIPickerView added to a UITableView that I present when a button is pressed, but when I scroll the table the UIPickerView goes out of view, and if I'm scrolled out of range of where I've presented it, the UIPickerView appears to have never been called.
Does anyone know how to accomplish this?
Thank

The use of UITableViewController is great unless you need to add subview that don't scroll with the table view. It can't really be done. The solution is to use a UIViewController instead and add your own table view, setup the table view dataSource and delegate protocols and replicate the basic table view controller plumbing.
Once your view controller works like a normal table view controller again, you can now add subviews to the view controller's view that won't scroll with the table.

if u add tableview programatically
SearchtableView.frame = CGRectMake(450, 90, 318, 600);
SearchtableView = [[UITableView alloc] initWithFrame:CGRectMake(623, 90, 400, 400)style:UITableViewStyleGrouped];
[self.view addSubview:SearchtableView];
//belove the tableview//
//Add UIPickerView to the self.view]//

Something told me that there must be a simpler alternative to the answers that I'd been given, and I found a solution.
I decided to find the y coordinate of the scroll point using scrollViewDidScroll: and then animating the UIPickerView to the desired location.
...
[UIView beginAnimations:nil context:NULL];
CGFloat pointY = self.scrollPoint.y;
[self.sortPicker setFrame:CGRectMake(0, pointY + 200, 320, 216)];
[UIView commitAnimations];
...
The UIPickerView will only appear if the scroll has been stopped so it's necessary to implement a method to stop the scroll on touch:
- (void)stopScroll:(UITableView *)tableview
{
CGPoint offset = tableview.contentOffset;
[tableview setContentOffset:offset animated:NO];
}
This will allow you to display and dismiss the UIPickerView at any moment at any given destination.

Related

Force Subview to fill parent

I have some subviews that I place inside each of my tab bar's view controllers. Right now I'm sizing it with a pixel count but it only works on the iPhone 4 and 4s and not the iPhone 5 because of the longer screen size. I could check for the device and then size it that way but I feel like there has to be an easier way to do this.
viewController1.view.frame = CGRectMake(0, 0, 320, 460);
I colored the subview yellow so it's easier to see.
You should NOT change frame of tabbar's content view controller's view. UITabBar takes itself care of sizing the child view controller's frame properly.
If you want to add subview to content view controller (controller under some tab) and make that view to always automatically resize with the controllers main view (self.view), you can use combination of superviews frame and autoresizing.
Example code (you can do this in - (void)viewDidLoad for example):
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:view];
If you want to do this by setting frame than DO this:
[childView setFrame:childView.superview.bounds];
The master view in your view controller should already be the size of the usable space on the sceen. In general, if you want a view to be the same size as it's parent, you can use view.frame = view.superview.frame, though I doubt that would be a good idea to call on the view controller's view.

iPad: Popover windows got resized iOS

CGRect rect = CGRectMake(0, 0, 1050, 900);
[wineAdminPopup presentPopoverFromRect:rect inView:master.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Hi I put the above code to make a popup in a tableview. However it doesn't popup in the whole screen. If I want to center it in the iPad screen with no arrow or arrow in the center. How can i do it. Thanks in advance.
The rect parameter in presentPopoverFromRect:... specifies the rectangle at which to anchor the popover, not the size of the presented popover. That would be specified by setting contentSizeForViewInPopover on the popover's content view controller.
If you don't want the arrows and don't need the specific behavior of popovers, then you could
present your view controller modally:
controller.modalPresentationStyle = UIModalPresentationFullScreen; // or UIModalPresentationFormSheet
[self.navigationController presentModalViewController:controller animated:YES];
presentModalViewController is deprecated in iOS 6 and above. Use presentViewController:yourViewController animated:YES completion:nil (parameters animated and completion can be set depending on your requirements). Also if you want to resize yourViewController you need to change self.view.frame and next time your view controller will be of that size.

Resize UIView from point with animation

I have UIButton on view, when I taped on this button I want to create new view and display it on iPad screen, how I can view this view like growing from button to full screen ?
Next time actually show some effort with what you have tried etc when asking for help
- (void)buttonTapped:(UIButton *)button;
{
UIView *expandingView = [[UIView alloc] initWithFrame:button.frame];
expandingView.backgroundColor = [UIColor redColor];
[self.view addSubview:expandingView];
[UIView animateWithDuration:.25f
animations:^{
expandingView.frame = self.view.bounds;
}];
}
On the button click event.
Create the view with frame with size zero and orgin as center of
button
2.add to mainview
3.Then using animation block change
the frame to orginal
What are block-based animation methods in iPhone OS 4.0?
use this qn to find how to add animation

I would like to implement a half UITableView half MapView UIView with a button in the middle

Well, this is what I want to do in my app: I would like to implment a UIView with a map on the top half of the screen and a tableview on the other half with two buttons in the middle. If I press one of the buttons the map will get fullscreen and if I press the other one the tableView will fit all the screen.
Any suggestion?
In one view controller like a UINavigationController create an MKMapView with a frame the size of the top half of the view and add it as subview of your view controller. Then I would create a UIToolbar to hold your buttons and make the top of it's frame line up with bottom of the MKMapView. Finally create a UITableView with it's frame just below the others (make sure you hook up it's delegates).
Then assign the target of your UIBarButtonItem that makes the map go fullscreen to a method that animates the frames of all three views like this:
[UIView animateWithDuration:0.24
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:(void (^)(void)) ^{
self.toolbar.frame = CGRectMake(0, MAP_HEIGHT_FULLSCREEN, 320, TOOLBAR_HEIGHT);
self.mapView.frame = CGRectMake(0,0,320,MAP_HEIGHT_FULLSCREEN);
self.tableView.frame = CGRectMake(0, MAP_HEIGHT_FULLSCREEN+TOOLBAR_HEIGHT, 320, MAP_HEIGHT_FULLSCREEN-MAP_HEIGHT);
}
completion:^ (BOOL finished){}
];
Create both views how you are planning, On one button click, change the frame of one view to fit the full screen, if you click the other button, do the same thing to the other view.

How to make detail view scrollable in master detail app

I have only been working in iOS for a few months but I have been banging my head against the wall for hours and hours for something that seems like it should be pretty straightforward. I used the master detail template in Xcode for an iPad app. I want the detail portion to be scrollable to show content below what is visible in the frame, in either orientation. I have tried numerous combinations of adding scrollviews in the DetailViewController in viewWillAppear, viewDidLoad, loadView...and the best I can come up with is what looks like a scrollable view on the top layer as it does show scroll bars and shows me that I did the scrollView.contentSize correctly as I can pan around, but the actual view with the fields and stuff doesn't move and the fields are unable to be edited. Here is my viewDidAppear as it stands at the moment. As you can see in the NSLogs I am trying to understand the view stack. If I uncomment the line before the logs, I lose the scroll bars altogether.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
scrollView.contentSize = CGSizeMake(2048, 2048);
UIView *parentView = [[UIView alloc] init];
parentView = [[self view] superview];
[[parentView superview] addSubview:scrollView];
//[scrollView addSubview:[self view]];
NSLog(#"%#", [parentView superview]);
NSLog(#"%#", parentView);
NSLog(#"%#", [super view]);
NSLog(#"%#", [self view]);
[scrollView setDelegate:self];
}
I would sincerely appreciate any guidance or tips on how to properly implement UIScrollView for this scenario.
You should add the UIScrollView in IB. Be sure to move all of your existing views and controls to be subviews of the scroll view. And you'll have to link the scroll view to an IBOutlet so you can set the content size in your view controller.
Instead of trying to wrap a uiscrollview around your main view's superview (which you have incorrectly tried to take ownership of (it should be NULL anyways)), why not herd your UI elements into a full-sized subview and wrap the scrollview around that? It would be much much easier.
Your hierarchy would look like this:
Self.view -> ScrollView (with contentSize set) -> UIView containing elements that need to be scrolled -> various UI elements