I'm trying to implent shyNavBarManager in my app:
I have a UITableview in storyboard and trying to use shyNavNarManager:
self.shyNavBarManager.scrollView = self.tbPertos;
but I'm getting :
NSInternalInconsistencyException', reason: 'You are using the component wrong... Please see the README file.'
Looking at the documentation:
NSAssert(navbar != nil, #"You are using the component wrong... Please see the README file.");
So it would seem that the navigation bar you are trying to assign here does not exist or is not initialized. See self.tbPertos
The answer isn't to check self.tbPertos, but instead, what is self. It must be a UIViewController subclass, since you are accessing the shyNavBarManager. However, it must be part of a navigation controller before you can start utilizing the component. So, move your code to viewDidLoad or somewhere after the component gets added to a navigation controller.
Note: I developed that library
Related
I have a problem with the navigation of my iOS app developed using Xamarin.
On any single view in my app, when I used at least one time the back button and popped a view controller, I may have to deal with this System.InvalidCastException on my main class :
Unable to cast object of type 'App.iOS.UI.PhotoTaker.PhotoTakerViewController' (Objective-C type: 'WorkZoneSelectorViewController') to type 'App.iOS.UI.WorkZoneSelector.WorkZoneSelectorViewController'.
Additional information:
Selector: viewDidLoad
Method: App.iOS.UI.WorkZoneSelector.WorkZoneSelectorViewController:ViewDidLoad ()
In this example, I was on a PhotoTakerViewController and used a PopToRootViewController to go back succesfully to the HomeViewController (this can also happen when I use the "back" button until I'm back on the HomeViewController). Then I tried to use a segWorkZoneSelector to display a WorkZoneViewController. This is where this error appeared. So, for a reason I don't understand, the app try to cast the last view controller I have loaded to the view controller I want to display right now. PhotoTakerViewController and WorkZone inherits from a common AppViewController. None of these 3 classes have an ExportAttribute
I'm not able to reproduce this error systematically.
Something odd with this error message is also the fact that it says that the app crashed on the method WorkZoneSelectorViewController:ViewDidLoad. But when I try to add some instructions at the beginning of the method, these are never called.
Failed to marshal the Objective-C object 0x7a71ed40 (type: SecondViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'NavigationApp.SecondViewController' does not have a constructor that takes one IntPtr argument).
I have a ViewController and secondViewController, When I hookup storyboard to secondViewController, the above error is shown. But without hookup with secondViewController, its working fine.
If you are waiting for some answer to your problem you might want to format it correctly and respect your readers.
You are literally throwing your error message to our face.
Have you tried to follow this guide ? https://developer.xamarin.com/guides/ios/application_fundamentals/ios_code_only/
I am trying to implement BWWalkthrough in my project. However I get an error stating
Unknown class _TtC20BWWalkthroughExample27BWWalkthroughViewController in Interface Builder file.
Could not cast value of type 'UIViewController' (0x195bca580) to 'AppName.BWWalkthroughViewController' (0x10042c3a0).
(lldb)
It is pointing at the below code
let walkthrough = stb.instantiateViewControllerWithIdentifier("walk") as! BWWalkthroughViewController
I don't know why this is happening. Any help would be appreciated.
Also feel free to ask for more code from my project.
Your storyboard doesn't seem to be linked to a BWWalkthroughViewController. Find where the view controller should be a BWWalkthroughViewController, and check if it is one.
I have same issue.
I can fix to set BWWalkthroughViewController, not BWWalkthroughPageViewController in my walthrough storyboard.
I had a similar issue
Unknown class WelcomeViewController in Interface Builder file. Could not cast value of type 'UIViewController' (0x7fff898d1f50) to 'SimpleLoginApp.WelcomeViewController' (0x108864c48).
Was able to resolve it by following these steps:
Open storyboard file
Select the View Controller that is not being identified.
Open Attribute Inspector and check if the "Module" text field is mapped with the appropriate app name.
In the IB make sure that you set the class of the master view controller into BWWalkthroughViewController, as well as the module BWWalkthrough. See the image . I just ran into this problem myself, easy step to forget sometimes.
Please follow these steps to fix your issues.
Create BWWalkthroughViewController ViewController Class.
Main StoryBoard
BWWalkthroughViewController
Show Identity Inspector.
Add BWWalkthroughViewController
Check again
I am trying to use HTAutocompleteTextField for iOS. I set the text field using the interface builder. Included the required data source and delegate protocols in my header file, and set the datasource/delegate to self in my controller. However, as soon as I hit either the call to set the delegate or the datasource the app crashes. I've checked the obvious to make sure I didn't have a nil HTAutocompleteTextField. Has anyone experienced this issue?
You need to make sure you set the class of the view in Interface Builder to HTAutocompleteTextField. This can be done in the right hand side panel.
(Above screen shot is a crop from the official Apple docs).
Recently I wrote some code where I tried to refer to an outlet on a UIViewController I'd just instantiated with [storyboard instantiateViewControllerWithIdentifier] and modify the subview that the outlet pointed to before presenting the ViewController. It didn't work because the ViewController's view hadn't loaded its subviews yet, including the one that my outlet referred to, so the property just gave me a null pointer.
After (with some struggle) tracking down the cause of my issue in the debugger, I Googled around and learned, through answers like this one, that I can cause the view to load its subviews without being displayed by calling the myViewController.view getter. After that, I can access my outlet without any problems.
It's a clear hack, though, and Xcode - quite rightly - doesn't like it, and angrily protests with this warning:
Property access result unused - getters should not be used for side effects
Is there a non-hacky alternative way to do this that doesn't involved abusing the .view getter? Alternatively, are there canonical/idiomatic patterns for this scenario involving something like dynamically adding a handler to be called as soon as the subviews are loaded?
Or is the standard solution just to replace myViewController.view with [myViewController view] to shut up Xcode's warning, and then live with the hack?
On iOS 9 or newer, one can use:
viewController.loadViewIfNeeded()
Docs: https://developer.apple.com/reference/uikit/uiviewcontroller/1621446-loadviewifneeded
I agree that forcing a view to load should be avoided but I ran into a case where it seemed the only reasonable solution to a problem (popping a UINavigationController containing a UISearchController that had yet to be invoked causes a nasty console says warning).
What I did was use new iOS9 API loadViewIfNeeded and for pre-iOS9 used viewController.view.alpha = 1.0. Of course a good comment above this code will prevent you (or someone else) removing this code later thinking it is unneeded.
The fact that Apple is now providing this API signals it can be needed from time to time.
Not sure how much cleaner this way, but it still works fine:
_ = vc.view
UPD: for your convenience, you can declare extension like below:
extension UIViewController {
func preloadView() {
let _ = view
}
}
You can read explaination by following URL: https://www.natashatherobot.com/ios-testing-view-controllers-swift/
merged Rudolph/Swany answers for pre ios9 deployment targets
if #available(iOS 9.0, *) {
loadViewIfNeeded()
}
else {
// _ = self.view works but some Swift compiler genius could optimize what seems like a noop out
// hence this perversion from this recipe http://stackoverflow.com/questions/17279604/clean-way-to-force-view-to-load-subviews-early
view.alpha = 1
}
If I understand you correctly, I think there's another fairly standard solution: move the outlet modification/configuration code into a viewDidLoad method (of the recently instantiated VC).
The topic is also discussed in this question.
It would require some restructuring, but it might give you a "cleaner" design in terms of MVC if your incoming VC handled its own configuration, and it would avoid the "You should never call this method directly" stricture on loadView.
You can call [myViewController loadView] to explicitly load the view, instead of abusing the .view getter. The .view getter actually calls loadView if necessary when called.
It's still not a very nice solution, since the UIView Documentation's section on loadView explicitly instructs that
You should never call this method directly