UIPIckerView in UIPopoverController - iphone

I'm not trying to resize the PickerView's height. I'm fine with having the default size, which I believe is 320 x 216. I created this code to present a pickerView in my popovercontroller, however, I get these messages on the console:
2
011-06-30 13:18:28.125 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value 1024.0 pinned to 216.0
2011-06-30 13:18:28.126 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value 448.0 pinned to 216.0
2011-06-30 13:18:28.127 MiGenome[64357:207] -[UIPickerView setFrame:]: invalid height value -16.0 pinned to 162.0
I don't know why I get this since I'm trying to use the picker default size in the popover. Here's my code. Thanks.
- (IBAction)presentSortPopover {
UIViewController *sortViewController = [[UIViewController alloc] init];
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, sortViewController.view.bounds.size.width, sortViewController.view.bounds.size.height)];
sortViewController.view = sortPickerView;
sortViewController.contentSizeForViewInPopover = CGSizeMake(320, 216);
sortPickerView.delegate = self;
sortPickerView.dataSource = self;
sortPickerView.showsSelectionIndicator = YES;
self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:sortViewController];
[self.SortPopover presentPopoverFromRect:_sortButtonPop.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[sortPickerView release];
[sortViewController release];
}

I had the same problem until I embedded the UIPickerView in a generic UIView with the same dimensions (0, 0, 320, 216), and set the view controller's view property to the UIView.
Also, I used the setPopoverContentSize:animated: method on the UIPopoverViewController to set the popover dimensions, rather than setting it on the UIViewController.
Hope that helps.

I think this line is the culprit.
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, sortViewController.view.bounds.size.width, sortViewController.view.bounds.size.height)];
try
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];

UIViewController has a method called contentSizeForViewInPopover.
If you set the expected size for your view controller using it (using a CGSize) you will be able to prevent the UIPopoverController from resizing itself wrong.

Related

issue in picker view inside popover

I am making application in Ipad i have taken one pickerviewController in Xib and i show it when user click on particular button now i am trying to put that picker view in popover
this is how i am trying to achieve this tast
pickerView.hidden=FALSE;
i have created outlet of picker and i unhide it here
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];
[popoverView addSubview:pickerView];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);
//create a popover controller
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect;
popoverRect.origin.x =323;
popoverRect.origin.y = 713;
popoverRect.size.height = 215;
popoverRect.size.width = 70;
[popoverController presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
now the Issue Is that my popover is displaying but it is totally black I am struggling on this please tell me what am i doing wrong or correct the code thank you for help
Seems your picker view is hidden somewhere in the pop over because the frame is not properly set yet. So try to set the frame of the picker view to be equal to the bounds of the pop over as a starting point:
pickerView.frame = popoverView.bounds;
But before adding the picker view as a subview in the pop over, you need to remove the picker view properly from the superview.
Now, by default Xcode will generate the IBOutlet as weak property, and this will cause the picker view to be deallocated when it is removed from the superview. So you will need to declare the picker view as a strong property first.
After that, you can remove it from the current superview:
[pickerView removeFromSuperview];
You should keep a reference to the pop over view controller, for example declaring it is a property, and call dismissPopoverAnimated to dismiss the pop over properly.

programmatically added tablview's scroll disabled

I added tableview to scrollview programmatically but it is not scrolling. While i tried the same using XIB. but it is working fine.
here is my code
CGRect frame = CGRectMake(30, 30.0f, 900, 300.0f);
eappTable = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
eappTable.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
eappTable.delegate = self;
eappTable.dataSource = self;
eappTable.scrollEnabled = YES;
eappTable.scrollsToTop = YES;
[eappTable reloadData];
[scrollView addSubview:eappTable];
eappTable = [[UITableView alloc] nitWithFrame:YourSize style:Table_Style]];
eappTable.delegate = self;
eappTable.dataSource = self;
eappTable.scrollEnabled = YES;
[scrollView addSubview:eappTable];
And set self.scrollView.contentSize
You have to set the Content Size of ScrollView.
Hope it Helps !!!
Try to enable bouncing (because if all cells size are smaller than the uitableview size it self, it won't scroll if bounce is set to NO) :
eappTable.bounces = YES;
[eappTable setContentSize:CGSizeMake(320, 680)];
I know this is not the answer you are looking for. But I would like to mention one point :
Never add tableview as the subview of your scrollview.
Important: You should not embed UIWebView or UITableView objects
in UIScrollView objects. If you do so, unexpected behavior can
result because touch events for the two objects can be mixed up and
wrongly handled.
From UIWebView Class Reference

Adding UIScrollView to view and sending it to the back

I have added few UI components using Storyboard (UILabel, UIImageView). I am trying to put UIScrollView in this view, below all other elements:
Here is my code right at the end of -viewWillAppear method (code from my View Controller):
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, 480);
scroll.showsVerticalScrollIndicator = YES;
[self.view addSubview:scroll];
[self.view sendSubviewToBack:scroll];
The reason why I need a UIScrollView is large amount of text in detailsLabel - I'm attaching code I use for handling this label programatically:
detailsLabel.text = #"Some long text taken from databse";
[detailsLabel sizeToFit];
detailsLabel.numberOfLines = 0;
detailsLabel.lineBreakMode = UILineBreakModeWordWrap;
What I am doing wrong? How do I put UIScrollView below all other elements of my main view?
Try this:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, 480);
scroll.showsVerticalScrollIndicator = YES;
[self.view insertSubview:scroll atIndex:0];
...
[self.view insertSubview:detailsLabel atIndex:1];
Put your code in ViewDidLoad . Then add the labels after you have added the UIScrollView to the self.View in the ViewDidLoad itself. So by default the UIScrollView would be added on the self.View and then your label. Now you can either add the label on the scrollview or onto the self.view .
I've followed the instructions in this answer and it worked great: I've changed the Custom Class in Identity Inspector from UIView to UIScrollView and added this line to my -viewDidLoad in the View Controller file:
[(UIScrollView *)self.view setContentSize:CGSizeMake(320, 700)];
Option One:
Declare detailsLabel in .h:
IBOutlet UILabel * detailsLabel; // MAP IT WITH NIB or STORYBOARD
give it property and Synthesise in .m.
here in viewDidLoad declare:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, 480);
scroll.showsVerticalScrollIndicator = YES;
[self.view addSubview:scroll];
[self.view sendSubviewToBack:scroll];
[scroll addSubview:detailsLabel];
// IT SHOULD WORK.
Option two:
If you have large amount of text to display, then you can also use UITextView, it has inbuilt scrollview. And you can also set its text edit property.

Could Not able to position the UITableView?

- (void)loadView
{
SettingsTitleBar=[[UINavigationController alloc] initWithRootViewController: self];
searchBar =[ [UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 40)];
searchBar.placeholder = #"Type your City Name";
searchBar.delegate = self;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
[searchBar setShowsCancelButton:YES];
[SettingsTitleBar.navigationBar addSubview:searchBar];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 85, 320, 392)];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 120, 320, 302) style: UITableViewStyleGrouped];
[tableView setDelegate:self];
[tableView setDataSource:self];
[self.view addSubview:tableView];
}
I Have a UITableViewController,
I have utilized the first 44 pixels height for title bar, and then the next 40 pixels of height for search bar(44+40). These are added as navigation controller subviews. then i am adding my self.view at 85 pixel from top, finally tableview has been added as child to the self.view . But table view has been overlapped with the Searchbar. I dont what is wrong with it. I tried to change various yPositions of tableview and self.view but still nothing happened.
Can anyone able to help me out from this ?
Note : I dont want to add SearchBar into UITableviewHeader Section.
U can make the view of size 320X436 and add the tabble view and search bar in that view...
I wouldn't add subviews to the navigationBar. Add it to the view.
As a sidenote: anything you alloc (or retain or copy), you should release or autorelease
I had trouble with this too, initially. Don't worry about adding the searchBar as a subview. Simply do this:
self.tableView.tableHeaderView = searchBar;
The searchBar will be treated like a header. You'll want to change the CGRect's size to (0,0,320,44), however.

How to position a TabBar programmatically

I am creating a view controller programmatically which is a UITabBarDelegate and contains a UITabBar.
UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 200, 320, 49)];
[self.view addSubview:tabBar];
I don't really want to hardcode the frame values in case the screen resolution changes or I use the view in a different context with a different height, for example.
I'm vaguely aware I can create the tab bar without these values and probe the window and tabbar for height and width to calculate the desired values but I'm struggling to achieve this. What I want to achieve is a tab bar of the standard width and height correctly positioned at the bottom of the enclosing view.
Maybe something like this:
UITabBar *tabBar = [[UITabBar alloc] init]; //init with default width and height
tabBar.frame = CGRectMake(0,
self.view.frame.size.height - tabBar.frame.size.height,
self.view.frame.size.width,
tabBar.frame.size.height)]; //place it at the bottom of the view
[self.view addSubview:tabBar];
[tabBar release];
EDIT:
I've realised thet the size of a newly instantiated UITabBar is zero. Probably your best bet is to use a UITabBarController, as it already sizes your UITabBar accordingly:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[self.view addSubview: tabBarController.view];