0

hi i am currently trying to load dynamically a view from the NIB file this is the code :

res1 = new View1();
var ptr = NSBundle.MainBundle.LoadNib("View1",res1,null).ValueAt(0);
res1 = Runtime.GetNSObject(ptr) as View1;

res1 has a button inside. the button view is initialized and is inside the res1 view.

but the outlet that i created in the interface builder on the button in NULL how can initialize the outlets?

dimka87il
  • 95
  • 6

1 Answers1

1

Try to use that way:

 //parameter 2 should be a controller.
 var ptr = NSBundle.MainBundle.LoadNib("View1",this,null).ValueAt(0); 
 var res1 = new View1(ptr);

Because return type of the ValueAt method is IntPtr, and your view has a constructor take care that, it can add another view.

ductran
  • 10,043
  • 19
  • 82
  • 165
  • why the second parameter should be a controller ? – dimka87il Sep 15 '12 at 20:51
  • All nib files must have an Owner, I think it should be an UIViewController, which can manage your view. But if you want to use the same cells across multiple table views that reside in different Nib files, you can use NSObject. More detail in this link: http://software.tavlikos.com/2011/04/03/uitableviewcell-nib/ – ductran Sep 16 '12 at 04:37