UISplitViewController's different layout behaviour for Custom Cells in Master Controller - ios

An UISplitViewContller's the master view controller (TAbleView) has 2 types of cell prototypes.The iOS's default one is working fine but my custom cell has layout problems so all the subviews are missing.
If I present the master view controller modally all the subviews in the cell are laid out correctly.That means it is not related with the constraints set inside the content view of the cell.
Is there something special that i need to care about?
Second cell's subview are missing.
How they should look like.
Edit:
If i debug the layoutSubviews, i see that coordinates of the labels are not right.
<UILabel: 0x7fa8f0de82f0; frame = (0 -21; 42 21); text = 'Subtitle';
opaque = NO; autoresize = RM+BM;
userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fa8f0de84a0>>
Constraints for the Subtitle Label

After playing around with constraints I figured out that the problem was related with the size classes.
You need to specify the constraints for Splitview's master in ANYxANY size class not anything else.Mine were added in Regular to Any.

Related

UICollectionViewCell gets hidden randomly

I have a UIView in which I am adding a UICollectionView to act as a banner view to look like a carousel. The Viewcontroller in which UIView is present, is part of pageviewcontroller.
PageVC --> UIViewController --> UIView --> UICollectionView.
Each VC has its own banner, so when the page is swiped, I reload the collectionView with the respective data and I am able to see it. Now if visit a page which I already visited, the collectionview cell disappears. The collectionview is visible but the cell is somehow hidden.
The collectionview cell is a customcell and I am not using any custom layout, I am using the default flowlayout. This is working fine in iOS8-devices.
Below is the debugger output,
When cell is visible:
CollectionViewCell: 0x7f9db8d9ffa0; baseClass = UICollectionViewCell; frame = (209 3.5; 209 96); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7f9dbb5dde60>>
When invisible (you can see its hidden now) the dequed cell is now hidden, no clue why it is happening
CollectionViewCell: 0x7f9dbb5897e0; baseClass = UICollectionViewCell; frame = (0 3.5; 209 96); clipsToBounds = YES; hidden = YES; opaque = NO; layer = <CALayer: 0x7f9dbb590220>>
indexPathsForVisibleItems is returning nil.
I was calling reloadData from multiple places which caused the system to get confused (may be) especially I have written reloadData in my updateconstraints method and hence for each minor constraint change reloadData was getting called.
Check all places from where you call reloadData for collectionview if you're experiencing the same problem.
I've encountered the same problem.
After
checking if the UICollectionView reloadData was called in some thread other than the MainThread
checking if there is any cases about multi-calling reloadData or updateconstraints
without solving my problem, I realized that in some occasions CGSizeZero was returned for collectionView:layout:sizeForItemAtIndexPath:.
When avoiding the CGSizeZero result, everything works well.
Same problem.
Here's my situation:
My collection view has a custom layout. I use the default flow layout without any problem.
When I use my custom layout, whose cell width is a half screen width. When I scroll to the 5th cell, all cells became hidden without reason.
Finally I found out that when I set cell's size correctly in the layout class of the storyboard, the problem is resolved.
Hope this helps.

How to enable touch events on tableHeaderView while the UITableView is still scrolling?

I've created a UITableViewController in my storyboard, and added a UIView as a tableHeaderView. I have an MKMapView in the tableHeaderView, but my problem is that the map in the tableHeaderView doesn't receive touches before the tableView completely stops scrolling. Rather if a touch occurs before the scroll ends decelerating, the scroll continues, and this is unwanted behaviour.
I've already tried subclassing the UITableView to override hitTest, but can't figure out what to return as the output of events within the tableHeaderView are as follows:
<MKNewAnnotationContainerView: 0x1589ac3a0; frame = (0 0; 375 310.5); autoresize = W+H; autoresizesSubviews = NO; layer = <CALayer: 0x170c3c5e0>>
So, is there a way to interact with the tableHeaderView simultaneously when the scrollView is decelerating?
It seems TableHeaderViews are not really made for things like this. You should simply add the MKMapView at the top of the UITableView, this will solve your problem.

.view Property of UITableViewController and UICollectionViewController

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.

IB Instantiated UIScrollView not scrolling

Yes, I have set the contentsize. When I do an NSLog of the contentsize I get a height of 0 and a width of 0 which is a little confounding. It seems like my scrollview doesn't actually exist.
I think I'm setting up the scrollview wrong.
In IB I have a viewcontroller subclass that has a scrollview, inside the scrollview are other labels/views/etc.
Does the scrollview need to have a single subview that manages the "actual" subviews or something?
When I run an NSLog on the scrollview it comes up with this:
Scrollview: <UIScrollView: 0x81b2960; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x81b2dc0>; layer = <CALayer: 0x81b7390>; contentOffset: {0, 0}>
The scroll view does not need to have a single master subview. I'd bet dollars to donuts you have forgotten to hook up the IBOutlet that should point to your UIScrollView in the xib file.
Okay, I figured it out, I needed to have the contentsize code in a viewDidAppear method not in a viewDidLoad method. It's weird because the other changes were being made, just not this one. Go figure

How do you autoresize a subview of a UITableViewCell for grouped mode?

I've subclassed UITableViewCell to add an extra label and some color options.
I added the label as a subview of [the cell].contentView. When you set a UITableView to "grouped" mode, it's indented from the sides of the parent view. The default subviews are moved a corresponding amount, but not ones you add. I set the added view's autoResizingMask to every possible value, but none takes the reduced width into account correctly.
The rect for the label subview is created in initWithReuseIdentifier as follows:
CGRect specialtyRect = CGRectMake(IMAGE_THUMBNAIL_SIZE + 3, 3, self.contentView.frame.size.width - IMAGE_THUMBNAIL_SIZE - 6, 16);
self.specialtyLabel = [[UILabel alloc] initWithFrame:specialtyRect];
[self.contentView addSubview:specialtyLabel];
Does anyone know why the red subview is behaving this way, and how to make the right end indent correctly to match the reduced width while the left end remains correctly offset from the imageView? Thanks!
I'm not using a UITableViewController, and I'm not loading these cells from a XIB.

Resources