By the way :  I would still like to know how to Register an override via 
Category.. It should "in theory" just be something to do with how the class is 
registered right?

Josh
________________________________
From: Josh Handel on behalf of [email protected] [[email protected]]
Sent: Friday, March 30, 2012 5:43 PM
To: [email protected]; MonoTouch Forums ‎[[email protected]]‎
Subject: RE: Category type "overrides"

Ok apparently what I needed to do was set some properties ON the bar before I 
archived and unarchived it.. (don't ask)

this code works for swapping out the implementation of the 
UINavigationController


UINavigationBar bar = navController.NavigationBar;

bar.TintColor = UIColor.FromRGB (49, 37, 27);

if ((UIDevice.CurrentDevice.SystemVersion.CompareTo ("5") >= 0)) {

UIImage image = UIImage.FromBundle (fileLoc);

bar.SetBackgroundImage (image, UIBarMetrics.Default);

return navController;

}

//int bgViewTag = 4242421;

NSKeyedUnarchiver unarchiver = new NSKeyedUnarchiver 
(NSKeyedArchiver.ArchivedDataWithRootObject (navController));

Class c = new Class(typeof(CustomUINavigationBar));

unarchiver.SetClass (new Class (typeof(CustomUINavigationBar)), 
"UINavigationBar");

UINavigationController controller = 
(UINavigationController)unarchiver.DecodeObject ("root");

((CustomUINavigationBar) controller.NavigationBar).BgFile = fileLoc;

return controller;



The only difference is that I set the UINavigationBar.TintColor.. which was a 
minor tweak I was adding to this build so that I could at least publish 
something for testing... Then bam it worked... so ya, SetClass must somehow be 
dependent on the instance that the archive was built from isn't in a default 
state..


Anyone else shocked that setting TintColor before creating an Archive (and 
unarchiving it) makes SetClass work???


Josh

________________________________
From: [email protected] [[email protected]] 
on behalf of [email protected] [[email protected]]
Sent: Friday, March 30, 2012 5:27 PM
To: MonoTouch Forums ‎[[email protected]]‎
Subject: [MonoTouch] Category type "overrides"

I am at my whits end trying to skin a UINavigationController in iOS 4.X (yes 
iOS 4.x not 5.X, 5 is easy, that is taken care of).

So time and time again I am brought back to having to somehow override or 
otherwise mangle the UINavigationBar.. So my question is this :

Can anyone show me how to override (or otherwise mangle) the UINavigationBar 
AND get it inside the UINavigationController ?  In Objective C, I could Swizzle 
to swap implementations or use Category to essentially write an override.

If not, then I guess I'll have to roll my own NavigationController from 
scratch. but I really would prefer to some how register an override as a 
Category as that is probably the "cleanest" way to go.

FYI: Here is some code I tried with no luck (this should have been an XIBless 
way to reconstitue the UINavigationController with an instance of my 
CustomNavigationBar but it didn't fly.


[Register("CustomUINavigationBar")]

public class CustomUINavigationBar:UINavigationBar{

public CustomUINavigationBar(IntPtr handler):base(handler){}

public string BgFile{get;set;}

public override void Draw (RectangleF area)

{

UIImage image = new UIImage (BgFile);

image.Draw(new RectangleF(0,0,this.Frame.Width, this.Frame.Height));

}

}


then this little pare of methods acting like a "factory"


public static UINavigationController CreateNavController (UIViewController 
rootView, UINavigationControllerDelegate navDelegate, string fileLoc)

{

UINavigationController newController = new UINavigationController ();

newController = styleNavController (newController, fileLoc);

newController.Delegate = navDelegate;

newController.PushViewController(rootView,false);

return newController;

}

public static UINavigationController styleNavController (UINavigationController 
navController, string fileLoc)

{


if ((UIDevice.CurrentDevice.SystemVersion.CompareTo ("5") >= 0)) {

UINavigationBar bar = navController.NavigationBar;

UIImage image = UIImage.FromBundle (fileLoc);

bar.TintColor = UIColor.FromRGB (49, 37, 27);

bar.SetBackgroundImage (image, UIBarMetrics.Default);

return navController;

}


NSKeyedUnarchiver unarchiver = new NSKeyedUnarchiver 
(NSKeyedArchiver.ArchivedDataWithRootObject (navController));

Class c = new Class(typeof(CustomUINavigationBar));

unarchiver.SetClass (new Class (typeof(CustomUINavigationBar)), 
"UINavigationBar");

UINavigationController controller = 
(UINavigationController)unarchiver.DecodeObject ("root");

((CustomUINavigationBar) controller.NavigationBar).BgFile = fileLoc;

return controller;

}


Despite the effort, the unarchive.SetClass() doesn't seem to actually change 
the class of "UINavigationBar" like it should. because the DecodeObject call 
just returns a NavigationController with the default UINavigationBar 
initialized.




Thanks
Josh
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to