I have a collection view which is setup with a UIPageControl. Each cell is one screen. Each cell also contains a table view, which has a header view that displays an image. Each page/cell has a different image. I set the size of the image view to be the size of the image, so each page's image view/table header is a slightly different size.
When scrolling the collection view, however I find that some of the pages are not displaying the correct information. The table view contents were of a previous page, as well is the image and it's size. Essentially, it is not calling my method which sets up the cell. I think this might be because of reusable cells but I don't know how to fix it or turn it off, as I haven't used collection views that much
Please Help
Thanks
Related
I am trying to build this view where I have a UI Image view with some labels below it. And then Below this I have a Collection view which has a few items. I am struggling to figure out how I could have this view such that the whole screen keeps scrolling up once i get to the collection view.
Right now, the image view and the labels below scroll, but then the collection view only scrolls within its constraints. What I want is the entire screen to scroll up so the collection view items fill the screen up. I have seen several other replies to similar questions but am unable to follow it.
Can someone help with what I am doing wrong here ?
For the best practice on mobile programming, you should not have a scrollable view in another scrollable view. If you do so, you will have the problem as you described that your child collection view starts to scroll while other elements like your imageview and labels stay there.
To achieve your point, you can simply use a collection view and have custom cells. Now your entire window has only one scrollable view so it looks better. Then you are basically have different cell types. On top you have a collection cell as image, then you have few collection cell as labels, and so on.
I am trying to present information about an object grouped into sections. It may be long, so each section uses a view to visually separate the areas and it is all in a scroll view.
The first subview has a text field that does resize to fit the text, and its parent view also resizes to fit the text field.
The second subview has a grouped table to display data. I want all of the data in the table to appear and there should be no table scrolling.
The third subview has more information but its contents are an empty view for the purposes of this demo. In the real app I may add an arbitrary number of custom subviews.
What I'm finding is that the first subview resizes appropriately but I cannot find the combination of layout constraints that will make the second subview size to fit the table and move the third view down.
What do I need to do to make the scroll view fit its contents, when the sub view's contents may resize? The table view is filling the available space in the parent view, but the parent view is not expanding to fit. I note that the third view has a top space constraint to the superview, not just to the view above it. That's visible in the screenshot below
I found a solution that like most solutions, seems obvious in retrospect.
I think my problem is that the interior tableview had no fixed height and since it also a scrollview, was trying to fit whatever was assigned instead of expanding to fit the interior content. I was able to solve my problem by adding a fixed height constraint in IB and hooking it up to an outlet in my view controller. Then in the controller:
-(void) viewWillLayoutSubviews{
[self.tableView layoutIfNeeded];
self.tableViewHeightConstraint.constant = self.tableView.contentSize.height;
}
Derp. In summary the table view needed a height so I set one.
Here's a screenshot, note the fixed height constraint on the right hand side:
I am creating a grouped table with two sections.In the first section i have 5 cells and in the second section i have two buttons in the lass cell of it.
I have created labels and buttons on each of the cells in the first section and the labels are populated dynamically by the values selected in the previous screen.
Everything works fine as expected,except the borders of the table view gets ruined,it looks like half drawn and incomplete.When i make the table view to scroll up and when its back in the original position,the top borders are spoiled and when i scroll to the bottom the lower borders of the group gets affected making them incomplete.
I am setting the label's and button's attributes in each of cell after initializing them in the viewDidLoad method.
Please suggest me an idea to solve this issue.
Thank you one and all
I am setting the label's and button's attributes in each of cell after
initializing them in the viewDidLoad method.
This is incorrect. You should save the texts for the labels & buttons in a model class & set them in the cellForRowAtIndexPath: method. As, you are not doing this in the aforementioned method, your cell is redrawn when you scroll and the texts are nullified.
The only UITableViews I have worked with thus far are sized to fill the entire page.
I'm trying to create a page in my app where I will have an image and a label on the top of the page followed by a UITableView to hold comments below it.
Something like this springs to mind: http://www.inquisitr.com/wp-content/fbb.jpg
My problem is if I add a UITableView below the image and label, when I scroll the tableview then only the UITableView cells scroll. Not the entire page.
How would I go about making the entire page scroll so that the label and image scroll off the page and more table cells appear?
Thanks.
Put your image and label in a container UIView, and then set that container to the tableHeaderView property of your UITableView.
You could try setting the tableHeaderView property of the UITableView to a custom view containing your controls.
I have several parts in my app where I use custom table view cells.
Their content is created with subviews.
The problem is that on some of these cells, the content does not appear at all or does not appear correctly until after the cell was selected for the first time.
One example is a custom cell which has a custom subview which can be set after its creation. This view does not appear at all before I selected the cell and its views were redrawn. Calling -[setNeedsDisplay] in the subview's setter method does not help either.
The problems was that I was using the cells themselves to calculate their height. For some reason, the subviews (which were part of the cell used to calculate the height) weren't appearing correctly in the cells that were used for the actual displaying.
Therefore my advice: Never use a UITableViewCell to calculate its own height. This may work in principle (it doesn't crash), but might bite you later in unexptected and hard-to-debug ways.