2016-02-25 73 views
0

我正在使用Xamarin + Mvvmcross開發應用程序。目前它在iPad Mini,iPad 2,3,iPhone 5S和6上運行良好。奇怪的是其中一個視圖在運行iOS 7.1的iPhone 4S上崩潰。所有測試均使用真實設備完成。DequeueReusableCell僅在iPhone 4S上崩潰應用程序

這裏的崩潰:

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

爲表源代碼是這一個:

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; 
    } 
} 

我也註冊自定義類這樣的viewDidLoad中:

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

我不知道爲什麼它只會碰撞一個d evice ...崩潰似乎發生在UIKit/CoreFoundation上。

+0

FIXED>它看起來像是由於某種原因,我有一個類型爲integer的運行時屬性,在我的xib文件中定義了值5。由於一些神奇的原因,iOS在7.1上崩潰,而在其他情況下崩潰。 – nhenrique

回答

1



您可能需要MessageCell筆尖註冊定製MessageCell類,像鑑於沒有負荷的方法。因爲第一次可能找不到帶標識符的單元。

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


要使用標識

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


我希望這可以幫助解決問題的deque細胞。

+0

對不起,我忘了添加上面。我已經在做它,否則它會崩潰的所有設備/ iOS的 – nhenrique

+0

包括上述缺少的代碼。檢查筆尖是否已分配類和標識符?請讓我知道是否解決你的問題。 –

+0

恐怕它仍然發生與這些更改相同的崩潰:/ – nhenrique