简体   繁体   中英

DequeueReusableCell crashes app on iPhone 4S only

I'm developing an app using Xamarin + Mvvmcross. Currently it's working fine on iPad Mini, iPad 2,3, iPhone 5S and 6. Strangely one of the views is crashing on iPhone 4S running iOS 7.1. All tests were done using real devices.

Here's the crash:

https://gist.github.com/nunohorta/2b84245899e8c0daa116

The code for the table source is this one:

    public class MessagesTableSource : MvxStandardTableViewSource
{
    UITableView _tableview;
    MessagesView _parent;
    UILabel messageLabel;

    private static readonly NSString MessageCellIdentifier = new NSString("MessageCell");

    public MessagesTableSource(UITableView tableView, MessagesView parent) : base(tableView)
    {
        _tableview = tableView;
        _parent = parent;
    }

    public override nint RowsInSection (UITableView tableview, nint section)
    {
        return _parent.ViewModel.Messages != null ? _parent.ViewModel.Messages.Count : 0;
    }

    public override nint NumberOfSections (UITableView tableView)
    {
        if (_parent.ViewModel.Messages != null && _parent.ViewModel.Messages.Count > 0) {
            return 1;
        } else {
            /*
             * Custom View here
             * 
             * */

            return 0;
        }
    }


    protected override UITableViewCell GetOrCreateCellFor (UITableView tableView, NSIndexPath indexPath, object item)
    {
        var cell = (MessageCell)tableView.DequeueReusableCell("MessageCell");
        return cell;
    }
}

I'm also registering the custom class like this on the viewDidLoad:

    tableView.RegisterNibForCellReuse(UINib.FromName("MessageCell", NSBundle.MainBundle), MessageCellIdentifier);

I have no idea why is it crashing just for one device...The crash seems to happen on the UIKit/CoreFoundation.



You may need to register MessageCell Nib to custom MessageCell Class, like in view did load method. Because for very first time it may couldn't found cell with identifier.

tableView.registerNib(UINib(nibName: "CustomOneCell", bundle: nil), forCellReuseIdentifier: "CustomCellOne")


To deque cell with identifier

tableView.dequeueReusableCellWithIdentifier("CustomCellOne", forIndexPath: indexPath) as! CustomOneCell


I hope it may help to resolve issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM