Bug 44495 - UINavigationBar does not expose IntPtr construction
Summary: UINavigationBar does not expose IntPtr construction
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.0 (iOS10)
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Alex Soto [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-09-19 14:58 UTC by David Lilley
Modified: 2016-09-20 14:14 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description David Lilley 2016-09-19 14:58:24 UTC
To be able to use a custom UINavigationBar the UINavigationController has a type of constructor.

new UINavigationController(typeof (BankingNavigationBar), typeof (UIToolbar));

Using the UINavigationController in this way requires for the UINavigationBar to have a IntPtr constructor which the base class is internal protected. So I cannot access it.

[Register ("BankingNavigationBar")]
public class BankingNavigationBar : UINavigationBar
{
        // does not exist base (nHandle)
        public BankingNavigationBar (IntPtr nHandle) : base (nHandle) //
        {
          
        }

         public BankingNavigationBar () : base () //
        {
          
        }
}
Comment 1 Alex Soto [MSFT] 2016-09-20 06:24:18 UTC
Hello David

While your statement is true, all of our IntPtr constructors are now protected internal (this was introduced with unified api [1]) nothing stops you using/exposing it in any subclasses of any NSObject derived types, even we use it in our default templates

>public partial class ViewController : UIViewController {
>	protected ViewController (IntPtr handle) : base (handle)
>	{
>		// Note: this .ctor should not contain any initialization logic.
>	}
>
>	public override void ViewDidLoad ()
>	{
>		base.ViewDidLoad ();
>		// Perform any additional setup after loading the view, typically from a nib.
>	}
>}

So I really do not see how you could not use it the way you want, the code you posted in comment #0 should compile just fine.

Could you please let me know how this isn't working for you? even better could you provide me a test case? 

Cheers!


[1]: https://developer.xamarin.com/guides/cross-platform/macios/unified/overview/#NSObject_subclasses_.ctorIntPtr
Comment 2 David Lilley 2016-09-20 07:27:49 UTC
Hi Alex,

Your absolutely right, I should have spotted that, I was perhaps a little too sleep deprived from young babies etc. 

I was just going on what intellisense was tell me, saying there is no base(handle) on () constructor.

Thanks 
Dave

(Made me smile to see your name, and thinking back to the PSPDFKit with Rene.)
Comment 3 Alex Soto [MSFT] 2016-09-20 14:14:40 UTC
Great to see that you sorted that out.

Cheers!

(Good old times :D I wasn't sure it was you heh glad to see you are doing Xamarin!)