Reputation: 1695
I have a view controller which registers for previewing in viewDidLoad method:
- (void) viewDidLoad
{
[super viewDidLoad];
if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] &&
(self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
{
[self registerForPreviewingWithDelegate:self sourceView:self.view];
}
}
but sometimes force touch is not recognized as if view controller didn't register for previewing.
Upvotes: 3
Views: 368
Reputation: 1695
The problem was starting the app from state restoration. Fix: place preview registering code in viewWillAppear:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] &&
(self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
{
[self registerForPreviewingWithDelegate:self sourceView:self.view];
}
}
When viewDidLoad is called from state restoration, the timing is right for registering for previewing.
Upvotes: 4