I want to create UITableView with map in beginning. Like in Foursquare app:
The trick is after scroll map should disappear like that:
How to do it? I'm thinking about using scrollview under the TableView, but maybe is a better solution. This can be done in interface builder?
Set your map view as UITableViews tableHeaderView. It will then scroll with tables content like in your screenshot
Short basic example code:
CGFloat mapHeight = 100.0f;
MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, mapHeight)];
// Do additional configurations of map view
self.tableView.tableHeaderView = mapView;
This code added to -(void)viewDidLoad will add 100pts in heightMKMapView to the top of UITableViewControllers table view
Related
I implemented a horizontal table view and it looks like this
The category bar, Dining Shopping something, is a horizontal table view and here is the implementation code.
LogInfo(#"Show Category Table start");
// add categories to be subview controller
self.categoriesTable = [[UITableView alloc] init];
self.categoriesTable.transform = CGAffineTransformMakeRotation(-M_PI * 0.5);
[self.categoriesTable setFrame:CGRectMake(0, 64, SCREENWIDTH, 44)];
self.categoriesTable.showsVerticalScrollIndicator = NO;
self.categoriesTable.showsHorizontalScrollIndicator = NO;
self.categoriesTable.pagingEnabled = YES;
self.categoriesTable.delegate = self;
self.categoriesTable.dataSource = self;
self.categoriesTable.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.superView addSubview:self.categoriesTable];
LogInfo(#"Show Category Table Finished");
self.categoriesTable.backgroundColor= [UIColor redColor];
It works as expect but if I change view, for example, I click any button to go to other view and go back to this view. The tableview looks like this
This problem also happpens even if I disable the bounce effect of the table view. Does anyone know how to solve this problem? Thanks!
Rather than applying a transform to the table to make it horizontal, use a collectionView with a horizontal layout.
Edit: If you want to continue using your current setup, try disabling automaticallyAdjustsScrollViewInsets on your view controller.
self.automaticallyAdjustsScrollViewInsets = NO
Edit 2: If you're curious, since iOS 7 every view controller looks at its topmost/first scroll view and adjusts its contentInsets to compensate for the navigation bar transparency which is enabled by default. In this case of course, such behaviour isn't desired at all.
I'm trying to implement an autocomplete UITextView. The auto-suggestion is working fine. But the UITableView is getting clipped off. Please look at the image below.
The greybox is the actual UITableView. This UITableView is defined in another .xib file and is being called from another ViewController.
autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, 320, 35) style:UITableViewStylePlain];
autocompleteTableView.delegate = self;
autocompleteTableView.dataSource = self;
autocompleteTableView.scrollEnabled = YES;
[self.textViewCell addSubview:autocompleteTableView];
here autocompleteTableView is the UITableView and textViewCell is the UITextView. And this is getting called from another ViewController which makes the autocomplete box to constrict to UITextView size.
What i want to achieve is something like this :
Your problem would appear to be because of the view you are adding the table view as a subview of. Even if the table view was visible it most likely wouldn't respond to touches because of the frame of the superview (taps outside the frame aren't handled).
You should consider doing something like adding a new view higher up the view hierarchy which replaces (overlays) the text field and adds the table view. This needs to be added high enough up the hierarchy that the host view is big enough to fully contain the new view (so, the view controllers view).
It should work if you handle the text field as you currently are but add just the table view at the top level of the view hierarchy.
I am creating a view programmatically. The view is fairly simple as it only contains an MKMapView which I want to fill the screen (with the exception of the navigation bar at the top).
Here is what I am doing to setup the MKMapView:
- (void)setupMapView
{
mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
mapView.delegate = self;
mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:mapView];
}
However, the MKMapView doesn't seem to fill the entire screen. If you look at the top of this screenshot there is a gap between the top of the map and the bottom of the navigation bar (which is added by the UINavigationController).
Please could someone suggest why this is happening and how I can fix it?
The frame of the view (self.view.frame) probably have an offset in the y position. This is to position it correctly in its superviews coordinate space. When you copy that frame onto your new view it is inappropriate because you are moving into a different coordinate space.
A cheap alternative that will work in 99.9% or cases is to use the view bounds instead:
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
Because this usually has an origin of zero and the full size of the view.
If we need to add multiple views say - a tableview, a mapview and 2 or 3 more views on a single scrollable screen, then what would be most efficient way to do it ?
And will it be suitable for an app from the point of memory management?
Please share your thoughts.
Here's how you can do it programmatically: just add them in your viewDidLoad (or possibly your viewWillAppear) methods.
- (void) viewWillLoad
{
self.myScrollView = [[UIScollView alloc] init];
//Configure scrollview here (frame, contentsize, contentoffset...etc)
UITableView *table = [[UITableView alloc] init];
//Configure table here (frame...etc)
[self.myScrollView addSubview:tableView];
//Continue adding other subviews here
}
Or you can do it visually using storyboards. Just drag the views that you want onto your storyboard and then cntrl drag to your .m or .h files.
And yes, iOS is designed for displaying multiple views at once. It is suitable.
I am creating an iPad app using the master-detail template available in Xcode 4.3. My master tableview is acting as a navigation menu for the detail view and the menu items will be fixed. So I basically don't exactly need the scrolling view, thus I have turned it off.
self.tableView.scrollEnabled = NO;
Now I have a requirement to display a footer like cell aligned at the bottom of master menu just like in Twitter iPad app. The cell should appear at the bottom in landscape as well as portrait modes. Can somebody give me some hints regarding how to implement this?
I read on some blogs about using a UIView and setting it to UITableView.tableFooterView, something like this...
// I'll have to do calculations of frame height/x/y for both orientations
// to make the view appear at bottom - IS THERE A SIMPLER WAY???
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 944, self.tableView.frame.size.width, 60)];
UILabel *logo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 60)];
logo.text = #"This is the Footer.";
[footerView addSubview:logo];
self.tableView.tableFooterView = footerView;
After looking at the app, I don't think the "footer" is part of the table. It looks more like a small view under the table. So the table is set up so it will stretch vertically but it's height is locked above the bottom view. Maybe it would be better to use a UIViewController and a UIView for you Master View instead of a UITableViewController. Then put your UITableView in the UIView and put your footer below it. Then configure the UIViewController to work with the UITableView as it did before.
Hope this helps.