UICollectionView items not showing after migration to Swift 2 - uicollectionview

After migrating my Xcode 6 project to Xcode 7, only the first UICollectionView in my app renders properly.
When I switch tabs the CollectionView doesn't render properly.
The app worked fine in iOS 8.
Example:
Here is a CollectionView header in the Storyboard.
When I run my app, I am getting a blank view.
Interestingly enough, when I use the View Hierarchy debugger, it
shows that the element in fact does exist.

So it looks like ios9 has a bug when rendering custom cells.
I would suggest creating your custom cells in xibs and then loading them from there.
Make sure to include this in viewDidLoad:
self.collectionView.registerNib(UINib(nibName: "SongCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "SongCell")
self.collectionView.registerNib(UINib(nibName: "SongHeader", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "SongHeader")

Make sure you add this line in viewDidLoad of your collectionView controller
self.collectionView!.registerClass(YourCustomMemeClass.self, forCellWithReuseIdentifier: "reuseIdentifier")

Related

Storyboards and UISplitViewController not working under iOS 7

I have an app that must support iOS 7-9. The views are laid out in storyboard, it's a tab bar controller, with each tab containing a split view controller.
Everything works fine, except with an iPhone running iOS 7. I have the following code to collapse the split view controller to show the detail:
UINavigationController *splitNav = self.navigationController;
UISplitViewController *split = splitNav.splitViewController;
split.delegate = self;
But on the iOS 7 iPhone, split is nil (as there is no split view controller under iPhone on iOS 7) so splitViewController: shouldHideViewController: inOrientation: never gets called and I'm stuck in a weird state.
I tried push the detail controller onto the navigation controller manually, but the view never loads (just get a black screen), although the controller logic executes.
Can I either set that behavior with with storyboard instead of in code or is there some other way to reference the detail of a split view controller that doesn't exist?

iOS9 - UITableViewCellContentView is covering up Controls inside Cell

I have made a custom UITableViewCell called "SwitchCell" that has a switch.
In iOS9 Only, using Xcode 7 beta, the Content view in the cell is on top of the switch. (See screenshot of View Hierarchy. You can clearly see that the content view of the cell is on top of the other views. ):
So all the touches to the UISwitch are intercepted, and the IBAction does not fire.
In iOS8, this is not a problem. See screenshot for iOS 8.4 simulator. You can see that there is no content view on top of the controls:
Has anyone had this problem?
I tried remaking the NIB from scratch, but the same result occurs.
My NIB is a freeform size view with No status bar. It has two outlets: one for UILabel, one for UISwitch.
EDIT: please make sure to check the answer below that asks to verify that the cell's root view is not just a UIView but a UITableViewCell. This issue may also be a side effect of this.
After more investigation and searching, i found my solution here:
Button in UITableViewCell not responding under ios 7
What fixed it for me was:
cell.contentView.userInteractionEnabled = NO;
This prevents the cell content view from taking over the touch events, even though it's on top of the other views.
This issue was not only happening on iOS9, but on iOS7 as well. In iOS8, the Content view was behind the controls.
Problem can be in .xib file for your cell. When you create cell in separate .xib, be sure to drag UITableViewCell on canvas, not UIView.
SWIFT
I had an issue where my buttons in my custom tableviewcell swift files were working just fine, but then I upgraded to Xcode 12 and then all of a sudden I couldn't access them anymore (meaning my taps were not being recognized). The cell content view seemed to be interfering in the hierarchy and this like saved me:
cell.contentView.isUserInteractionEnabled = false
I put the line in cellForRowAt.
Thank you to #FranticRock
I had this problem when I was reusing a cell as a .xib. I didn't realise but when I first created the xib the default view that it created was in fact a UIView and not a UITableViewCell. It seems that at some stage UIKit adds the content view on top of my other elements and therefore interrupts certain events (e.g. touch events).
I resolved this by opening my xib file and dragging a UITableViewCell onto the canvas and copying my UI elements from the old view to the new cell.
Afterwards, additional settings also became available in the attributes inspector that matched those for a UITableViewCell.

ios8 unwind segue not working with UINavigationBarController and UITabBarController (Fixed in iOS 8.1)

I just started testing my iOS7 app on iOS8 with Xcode 6 (beta 6). I am aware that iOS 8 has deprecated the "push" and "modal" segue but I was happy to find that all my segue's worked... except one.
I built a demo app to show that unwinding from a modal segue seems to be broken if your app uses a UITabBarController with UINavigationController. (I saw another unwind segue post, but it was using swift, where as my demo app is using obj-c).
Here is what I am seeing more specifically:
[UITabBarContoller] -> [UINavigationController] -> [SomeViewController] -(Modal Segue)-> [This ViewController Cannot Unwind]
Interestingly, you CAN unwind if you do another modal segue:
[UITabBarContoller] -> [UINavigationController] -> [SomeViewController] -(Modal Segue1)-> [This ViewController Cannot Unwind] -(Modal Segue2)-> [This ViewController CAN unwind]
I also found I can unwind if I remove either the UITabBarController or the UINavigationController, but I do not plan on changing my entire app UI architecture :)
From what I can see, the root view controller never receives a call to canPerformUnwindSegueAction:fromViewController:withSender: which it does in iOS7.
My Question: Is there a different way I should try to get my unwind segue to work?
Thanks for reading.
Demo code is here: https://github.com/nmsasaki/UnwindDemo
UPDATE
This issue seems to have been fixed by iOS8.1. (The iOS 8.0 work around of creating a custom subclass of UINavigationController continues to work.)
Override viewControllerForUnwindSegueAction in UITabBarController by create a custom UITabBarController and use the custom one.

iOS7 Storyboards: App crashes after calling addSubview

I am working with the iOS book "Hello iOS Development". I coded along the book and just finished chapter 4. After implementing everything like in the book my app crashes.
I guess it's because I used Storyboards (Xcode 5 and iOS7), the author uses XIB files. Here's an image of the error:
What does the error mean? What's wrong with it? Does the addSubview refer to the XIB files I don't use due to Storyboards?
I'd really appreciate your help with this!
You cannot simply alloc] init a view controller whose view is defined in a storyboard or XIB file, as you have. Doing so will not yield what you expect.
If you are using a storyboard, you should give your card view controller an identifier in the storyboard, and then [self.storyboard instantiateViewControllerWithIdentifier:#"_CardViewControllerIdentifier"];
This will create a view controller with a view as set in the storyboard.
If you do not use a storyboard, but a xib file, you should use initWithNibName:bundle: to instantiate your view controller.

How to replace the FirstViewController in a TabBar app with another view controller (Kal)?

I created an empty iPad TabBar application using XCode 4, without storyboards. I placed that app in a workspace. I then added the Kal source (obtained from the iPad Juice build) to the workspace as a separate project. The initial build was clean.
I then went to the Kal example (NativeKal) and added EventKitDataSource.h and .m, and NativeCalAppDelegate.h and .m. (The image below shows what files are in the example project)
This is the code from the NativeCalAppDelegate.h file:
I tried setting the first TabBar UIView controller to "KalViewController" as I would normally do when using Storyboards, but it isn't listed in the drop down list of classes.
The question is: how do I get the NativeCal example view controller to replace FirstViewController in the in my TabBar application?
Comments added as Answer.
My recommendation is to switch to storyboards it is a lot easier to do UITabBarControllers in them. You can do this by just creating a new storyboard and copy and paste everything into it and then control drag from the UITabBarController to the UIViewControllers that you want to be linked to the tab bar controller and it does the rest for you, everything else is the same after that. In storyboards you can set the first view controller to be loaded so if you need it to be KalController then you can set it when you set up the UITabBarController. You can also set this in the code. I found that storyboards were a great new feature to xcode, UITabBarCotrollers are a lot easier to do in them then in .nib files I could never get them to work.
Hope this has helped.