I have the following views set up in IB for my project: UITabBarView->UINavigationView->MyCustomViewController.
I added a UISegmentedControl and a UITableView to the CustomView via IB by just dragging them onto the screen. I would like my app to look very similar to the AppStore app. Everything looks fine in IB; however, once it populates the UITableView with data, it covers the whole underlying view with a single cell (the segmented control is covered).
I didn't want to have to do everything in code so I've tried to stick with IB since this seems simple enough. Does anyone know why my UITableView is taking up the whole frame?
I figured out what was going on. I was incorrectly re-sizing the table view cell when binding the data. I ended up using the new prototype cells in the storyboard instead of trying to create a separate nib.
Related
Hi I'm currently attempting to create a very complex TableViewCell which will be used once and presented at the top of our TableView. The view consists of
4x UILabel
2x UICollectionView
1x UIImage
I'm wondering whether this is feasible and what the best way to approach this is?
I'm open to this not being a UITableViewCell but we want this to seamlessly scroll with the rest of the TableView, putting this within its own container above the TableView and within a UIScrollView was pretty messy as we had to handle the scrolling for both the scroll view and the tableview.
OK - my suggestion would be...
Create a new ViewController - MyHeaderViewController
Layout this view, including the 2x UICollectionView
Get it working on its own
Once you've got that part going...
Create a new ViewController (can be a UITableViewController, or a UIViewController with a UITableView added)
add code in this controller to load MyHeaderViewController, and then set the tableHeaderView = myHeaderVC.view
That let's you keep all the logic for the Collection Views separate from the TableView
See https://github.com/DonMag/SWTableHeaderView for a simple example.
I seem to be having a very strange problem with my UITableview cells and autolayout. So my tableview is set up as follows:
I have a UITableView within a UIViewController that I created via Interface builder using Autolayout
My tableview is using UITableViewAutomaticDimension so that the cells can resize based on the text within them.
Each cell has 2 subviews within it. A front view and a back view. The back view contains the buttons for my slide-able cells
I am using NSFetchedResults controller to update the tableview
The problem occurs when I tap on a cell and am taken to the next view. Then I create a core data item within that view and save so that it is inserted into my tableview (now behind the current view controller).
What happens is that the newly inserted cell seems to lose all autolayout constraints and all view elements are on top of each other in the top left of the cell. It also looks like they are not even contained within the front view for the cell (or the front view has a width and height of 0).
Example:
It gets even stranger. If I refresh the tableview by pulling down and the cells are reloaded it corrects itself. However, if I refresh the tableview again then the problem appears again but on a different cell. This bug does not happen consistantly which is rather frustrating.
Any help would be appreciated as I only have a few remaining hairs on my head to pull out at this stage.
Thanks in advance!
So I found out what the issue was. The issue was that I was using size classes in Interface builder but I was only using the iPhone Portrait size class and did all my work in there instead of the "any" size class. Disabling size classes and setting the project to iPhone only fixed all these problems.
Weird I know
I need to have iOS app with screen like this:
screen
The idea is when user start to scroll down the first UIView to move up until the second UIView reach the top where it will stick and only UICollectionView will continue to move up.
Currently I'm using this structure
UIScrollView (main scroll)
UIView (some banners)
UIView (UISegmentedControl)
UICollectionView (grid with items, scroll is disabled, main scroll is used)
I manage to do it, but I needed to set UICollectionView height constraint manually in the code (calculated based on all items in grid) in order to appear in UIScrollView (everything else is handled by AutoLayout in Storyboard). The problem with this is that UICollectionView think all cells are visible and load them, so the whole recycling & reusing thing does not work. It's even worst because I use willDisplayCell method on UICollectionView to load more data when last cell is displayed, but now it load all pages at once.
My question (actually they are 2)
How can I fix the issue above?
What is the right way to achieve this functionality? Maybe my whole approach is conceptually wrong?
Collection view is a scroll view itself. So maybe you could have same functionality only with Collection view with sections or even custom layout?
I have a UICollectionView as the top view on my view hierarchy in IB. It's making use of a custom layout that splits the cells (registered from nibs) along the left and right edges of the view, with decoration views behind and a supplementary view the size of the entire view on top of the cells. All of that works as expected.
What doesn't work is that selecting cells is simply not being registered. They're not firing calls to collectionView: didSelectItemAtIndexPath: (the delegate is set correctly), nor is the highlighted state of the images within the nib working. It's acting rather like a view higher up is consuming the tap, but the collectionView is the top view. I've tried removing the overlaid supplementary view and background decoration views, and also tried temporarily converting to using a flow layout in case my custom layout was doing something screwy - still nothing. Making this even more frustrating is the fact I'm using collectionViews on other view controllers in this app (governed by flow layouts), and they work perfectly fine without any special customisation. I'm out of options, any ideas?
Problem solved. Turned out the nib I was using had a single view that was, for some reason, an instance of UICollectionReusableView, not UICollectionViewCell. Presumably, the reusable view class is designed to not allow selection by default.
Take this about page for Things:
I'm having trouble creating something similar. I just want a UITableView under a UIView with a UIImageView and a UILabel in it.
If I use a UIViewController and so I can position the UITableView downward, I get this error: "Static table views are only valid when embedded in UITableViewController instances."
If I use a UITableViewController with a grouped style and use contentInset on self.tableView to move it down ([self.tableView setContentInset:UIEdgeInsetsMake(150,0,0,0)];) I can't figure out how to place a view above it. If I try to attach anything to self.view it crashes (obviously). Same happens if I attach anything to self.tableView.
I then tried making the UIView the header of my UITableView section (I only need one section) but I can't get it to move up enough. It just sits inside the UITableView almost.
How do I have a UITableView (grouped style) exist with a UIView above it?
This can be achieved easily using the tableHeaderView property of UITableView. If you are using Interface Builder (which it looks like you are), then you can just drag a UIView above the table view and it will be set as the table's header view. All you need is a UITableViewController; no need for UIViewController and manually laying it out.
That's because the view probably isn't placed on top of the table but rather within the table's section 0 header. Or, even more likely, the view in question is just a regular UITableViewCell with a 0 alpha background.
Either of these options would allow the top view to be scrolled out of frame as the user scrolls under every condition.
I recommend [MDAboutController] (https://github.com/mochidev/MDAboutController)
It's easy to integrate and you don't have to waste any time configuring the UITableView.