I created an iPhone app where it came with the UINavigationController and UITableView predefined.
I want to add an UIView on the top of the screen but every time user scrolls tableView, my view also scrolls. Is there anyway to make the view independent from the tableView scroll?
Thanks
Don't use UITableViewController, use UIViewController and add UITableView as a subview
Create your view and set it as table header view of your table view.
UIView *yourView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
[self.tableView setTableHeaderView:yourView];
It will not scroll with tableView but always remain on top of table view.
Related
I have a UIViewController(in Objective C) which contains various subviews. Now I have added a new UIView(swift file and a xib file) as a subview to this view controller. In this UIView I have dragged and dropped UITableView and set datasource and delegate to file owner. Also, I have created a separate UITableViewCell class(in swift).
I want to add this UITableViewCell in UITableView(created in UIView). And add this entire view as a subview to UIViewController. The frames of the UIView are set in view controller
When I added this UIView as subview tables and cells are not displayed and tried various methods but either the app crashes by tableview as nil or the cell is not loaded at all and rows are not displayed
Please help me out!!!
Thank you
Code Snippet:
UIViewController
- (void)addNewView() {
NewUIView *view = [[NewUIView alloc] initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, self.view.bounds.size.height)];
[self.contentScrollView addSubview:view];
}
UIView(NewUIView)
Here I have added an outlet of UITableView with delegate methods of UITableView in extension(connected delegate and datasource from xib file to file owner).
And add cell
UITableViewCell
I want want to add this cell to UITableView In UIView.
I'm using parse's PFQueryTableViewController, which is almost exactly the same as a UITableViewController except it handles some querying in the background.
My goal is to place a static toolbar at the bottom of the screen. I decided to do this by giving tableView a smaller frame, and creating and adding my toolbar subview below the tableView, as a subview to the same view that the tableView is a subview of.
Here's a photo. I am trying to add my toolbar to the little white space at the bottom of the screen. That whitespace does NOT scroll with the table view:
I have tried [self.view addSubview: toolbar], however, this just adds it to the tableView, and as a result, my toolbar scrolls with it. I can't seem to find any documentation on the view hierarchy for a UITableViewController. Anyone know where I should add my toolbar subview? I should also mention that all of this is sitting inside of a UINavigationController.
A PFQueryTableViewController (like all UITableViewControllers) has a table view as its view.
If you want to have other views within the view controller, either don't use a table view controller, or subclass UINavigationController.
Alternatively, you can set the view controller's toolbarItems property, and the navigation controller will take care of making and configuring a standard toolbar.
implement viewFAorHeaderInSection delegate method of UITableView:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 90)];
customView.backgroundColor = [UIColor blackColor];
return customView;
}
and heightForFooterInSection
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 80;
}
it should solove your problem.
I have tall tableView and I want to add view on it, I want that it too will be tall.
I add view with this code but it only in one view height - 568 points.
_backgroundSelectionView = [[UIView alloc]initWithFrame:self.tableView.bounds];
_backgroundSelectionView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
[self.tableView addSubview:_backgroundSelectionView];
How can I add view on all screen?
UITableViewController provides UITableView and you cannot add subviews to tableViewController on top of tableview easliy.
Instead of using UITableViewController change it to UIViewController(which will conforms to UITableViewDataSource and UITableViewDelegate), with this you can add views(tableView and any other subView) on main UIView of UIViewController.
I have a UITableViewController. In the UITableView I have a subview - ImageView. ImageView this is my header of TableView. I want that header (ImageView) is always on top when I scroll.
I have the following code which work on IOS 5, but does not work on IOS 6:
- (Void) scrollViewDidScroll: (UIScrollView *) scrollView {
[ImageView setFrame: CGRectMake (0, self.tableView.contentOffset.y, 320, 100)];
}
So, what should I do to solve this problem on IOS 6?
The header and footer in UITableView and UICollection view are fixed inside there container scrollview. What you need to do is actually place a button outside of your UITableViewController and added after that controller either in Interface builder or when setting up your VC in viewDidload. This will then be above the scroll view. You might want to resize the UITableViewController so that the content doesnt pass under the button.
I am doing a slide menu using a UITableView and I have 2 options on the menu and I want to put a button at the bottom like in this image:
I try to do that add a tableFooterView like that.
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 500, 320, 70)];
footerView.backgroundColor = [UIColor blackColor];
self.tableView.tableFooterView = footerView;
However, the view appears just after the second cell, but I want it at the bottom.
Thanks for help.
No you shouldn't add any empty cells, that's just hacky. If you really need the button to be at the bottom, you should use layoutSubviews to control the frame of the tableView and the footerView.
- (void)layoutSubviews
{
[super layoutSubviews];
self.tableView.frame = // top 80% of the screen
self.footerView.frame = // bottom 20% of the screen
}
You should know that every UITableViewCell has its height and footer is part of a UITableView and will appear at the bottom of a UITableView. If you want to make your UITableView look like what that image shows, you should make sure that your cells are high enough to make sure that your UITableView are high enough so that footer will appear at the bottom of UITableView
My suggestion is to add extra "empty" cell(I mean a cell with no content but has a height).
Add a Container View with View Controller from storyboard. You can use autoresizing to set the buttons on right place.