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.
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 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.
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 am trying to add UIView *separatorView at the top of my collection views and table views which appears when the respective view's contentOffset.y > 0. I have made this work on my collection view by adding the view in viewDidLayoutSubviews and added it to self.view. Then by using some of the scroll view delegate methods I can make it show and hide. This works well but for the table view, if I use the same concept the separatorView scrolls with the table view. I am still adding the separatorView to self.view but it behaves differently than on the collection view. I don't want the separatorView to scroll. I want it to stay at the top. Am I correct in believing that the way to make this work for the table view is to subclass UIViewController and manage a table view within that along with the separatorView? Is there any way to make it work in my current UITableViewController subclass?
Basically, why does self.view scroll with the table view and not with the collection view? This seems inconsistent.
Thanks for the help.
Edit: Added picture to demonstrate idea.
self.view in a UITableViewController is a UITableView because the tableViewController overrides loadView on the view controller.
If you run the following code:
UITableViewController *tableViewController = [[UITableViewController alloc] init];
NSLog(#"%#",tableViewController.view);
You would get the following console output:
2014-05-13 21:19:02.823 Test[28681:60b] <UITableView: 0x109834200; frame = (0 20; 320 548); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x109548f00>; layer = <CALayer: 0x109548c40>; contentOffset: {0, 0}>
As you can see, self.view is not a UIView but instead it is the UITableView. Your separator view scrolls with the tableView because calling:
[self.view addSubview:separatorView];
is exactly the same as calling:
[self.tableView addSubview:separatorView];
If you wanted the separator to stay in a fixed position it would need to be added to the tableView/collectionView's superview and not the scrolling view itself.
The reason this is not happening in the UICollectionViewController is because self.view is actually a UICollectionViewControllerWrapperView object. This is a private class but judging by its name, I am assuming it is a UIView that wraps the UICollectionView.
The most sensible way to achieve what you want would be to use a custom container view (child view controller) that would be a UIViewController subclass containing your separator view and tableView/collectionView controller.
If you didn't want to add a child view controller then the other alternative would be to like you said, create a UIViewController subclass and add your separator view and tableView as a subview within the view controllers view however if you don't use a UITableViewController you lose bonus functionality like automatically adjusting the tableView's contentInsets for keyboard appearance etc.
I have a UITableViewCell which contains an UIView.
This UIView is larger than the UITableViewCell and should also be visible in the cell above.
clipsToBounds=NO
did not work.
This does only work when I remove the content from the upper cell and set the background color to clear.
This means, the content in my upper cell covers my UIView, that's why I tried to call bringSubViewToFront, but this did also not work.
What am I doing wrong?
This is how I add the custom UIView to the cell's contentView:
CustomView *view=[[CustomView alloc] initWithFrame:CGRectMake(0, 0, [DeviceInformation getWidth], [self tableView:tableView heightForRowAtIndexPath:indexPath])];
[cell.contentView addSubview:view];
and in my CustomView I am adding another UIView, which should be then presented among multiple Cells.
Thanks!