UIImageView returns null instance from Storyboard

ArvisArvis USMember ✭✭
edited June 2014 in Xamarin.iOS

Made custom UITableViewCell class using storyboard designer. It successfully generated partial class:

                   [Register ("VehiclesTableCell")]
                   partial class VehiclesTableCell
                    {
                        [Outlet]
                        [GeneratedCode ("iOS Designer", "1.0")]
                        MonoTouch.UIKit.UIImageView troImageView { get; set; }

                        void ReleaseDesignerOutlets ()
                        {
                            if (troImageView != null) {
                                troImageView.Dispose ();
                                troImageView = null;
                            }
                        }
                    }

when running app ImageView always has null reference, so i cant use that property in code:

    partial class VehiclesTableCell : UITableViewCell
    {
        public VehiclesTableCell(IntPtr handle)
            : base(handle) {
        }

        public void UpdateCell(UIImage troImage) {
            troImageView.Image = troImage;  // null reference exception troImageView
        }
    }

Does storyboard not suppose to instantiate all of its subviews automatically?

Posts

  • ArvisArvis USMember ✭✭

    Post images from involved classes: TableViewController, TableSource and TableViewCell.

  • JacobSlusserJacobSlusser USMember ✭✭

    arvis,

    I'm having the same issue. Did you find a solution?

    Thanks,
    Jacob

  • ArvisArvis USMember ✭✭

    @JacobSlusser‌ , actually i did.
    Let me remember what i did :)

  • ArvisArvis USMember ✭✭
    edited August 2014

    I used new cell reuse pattern mentioned in: http://developer.xamarin.com/guides/ios/user_interface/tables/part_2_-_populating_a_table_with_data/ in "Cell Reuse in iOS 6" part with new cell register method: TableView.RegisterClassForCellReuse (typeof(MyCell), MyCellId);

    But this pattern actually returns not properly instantiated cell items (all of them is null), so i just remove that cell reuse registration method from my controller. Because when using Storyboard with custom cell, it always return cell (not null) even if it not exist. So there is no need to check for null either in overridden GetCell method in TableViewSource class.

    So this is some kind of MonoTouch bug.

Sign In or Register to comment.