how to navigate from one viewcontroller to second viewcontroller in xamarin ios? - ios

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/

Related

Xamarin iOS. InvalidCastException during navigation

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.

Delegates in Xcode 7, iOS9

First of all, I am not Objective-c developer, however I have 4 years of experience in C and C++.
I am trying to make a few demo programs for an (iPad) app camp. For one of these programs I want to pass data between two UIViewControllers.
I have tried various examples, among the example below.
Passing Data between View Controllers
The code is written in an older version of Xcode so I took a bit of tweaking to get it through the compiler. Now I am facing the following problems:
It seems the prepareForSegue is not being called when I open a new view? (Or am I doing something wrong?) I have tried various ways.
In the same post there is a way to pass a delegate to a new class and back to the calling class. When I run this all goes good but there is the last part:
In ViewControllerA.m implement the following method from our protocol
(void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
{
NSLog(#"This was returned from ViewControllerB %#",item);
}
Does net execute... I have no idea what is wrong. I followed the example exactly. I can see the second view opening and closing, only the delegate code won't run. Do I have to do this in a different way in Xcode 7?
P.S. I know this is a basic question but I cant seem to find the answer or a good Xcode 7 guide anywhere.
following method from our protocol.. Does net execute...
Are you sure that you assign your first view controller's reference to your target view controller's delegate property like,
secondViewController.delegate = self;
You can do this in where you create the second view controller, e.g prepareForSegue method. If you forgot this your delegate method simply not work, because your second view controller doesn't know who's its delegate.

You are using the component wrong shyNavBarManager

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

iOS Delegates instead of passing data through a segue

I'm trying to learn how delegates work and wrap my head around the concept. I'm finding I get some of the ideas. I understand you use it to pass data from one view controller to another, however wouldn't it work the same if I just sent data from a segue and every time the 1st view controller would appear, it would use that data?
So for example I have 2 view controllers.
1 is homeViewController and
2 is editViewController.
I have a variable titled "addressOfHome" which is a string in homeViewController(1).
In homeViewController under the method "viewDidAppear"
I also set the addressLabel = addressOfHome.
Then I just pass the data from editViewController(2) to homeViewController(1)
when the segue's destination vc is homeViewController ?
I'm terrible at explaining things so I apologize for that, but I gave it my best shot. Thanks for your time!
Delegates are mainly used to "trigger action" on an object from another one.
An object delegates a way to handle something to someone else, for example when you click on an UIAlertView button, if its delegate is set on a viewController, alertView:clickedButtonAtIndex will be executed on the VC, which can so react as it want
I'm terrible at explaining things
Haha, yes, you are !
A delegate isn't for that - a delegate is a way to over-ride the default behaviour of some feature(s) of a class, without creating your own sub-class. See this post : How does a delegate work in objective-C?
Are you trying to understand how delegates work (in which case, I don't think your example is one that requires a delegate) or are you trying to implement the functionality you describe, and think that a delegate is the way to do it? (I think you actually want a data source).

Who calls the private method during unwinding in Xcode?

For implementing unwind segue we need make control-drag in the storyboard and
create private method in the destination view controller.
I don't understand : if method is private, how it works? Because in the implementation file of my view controller this NOT calling.
When executed, your application parses the .storyboard file at first, getting to know what classes it needs to instantiate and other important information, like segue connections. Then, it creates class instances (and manages them later). Then, when requested (e.g. after a button press), it attempts to find a method unwindToList: in the controller instance. If there is one, it would execute. If not, an exception would be thrown.
However, that method is not exactly hidden. Basically, there is no such thing as a private method in Objective-C; at least not in the same way as some other languages have. Every method is accessible by the runtime. If you're interested in how Objective-C works exactly, take a look at these pages, for example:
How does objective-c handle method resolution at run-time?
http://cocoasamurai.blogspot.ru/2010/01/understanding-objective-c-runtime.html

Resources