在使用自定义UITableViewCell Monotouch的UITableView上的GetCell期间出现SIGSEGV错误

时间:2014-02-25 21:49:45

标签: ios uitableview xamarin.ios xamarin sigsegv

我正在构建一个Xamarin.iOS应用程序,我有一个带有自定义UITableViewCell的UITableView,当我从服务器向表中添加数据时,或者如果我开始快速向上和向下滚动,应用程序崩溃并给我这个错误日志:  本机堆栈跟踪:

>0   CardReader_iOS                      0x003b5ed5 mono_handle_native_sigsegv + 260

>1   CardReader_iOS                      0x003befad mono_sigsegv_signal_handler + 176

>2   libsystem_platform.dylib            0x3a600063 _sigtramp + 42

>3   CardReader_iOS                      0x000d0798 

CardReader_iOS_ICTableContactSource_GetCell_MonoTouch_UIKit_UITableView_MonoTouch_Foundation_NSIndexPath + 164

>4   CardReader_iOS                      0x002740d0 

wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200

>5   CardReader_iOS                      0x003c1087 mono_jit_runtime_invoke + 1134  

>6   CardReader_iOS                      0x003fbd2d mono_runtime_invoke + 88

>7   CardReader_iOS                      0x003914af 

native_to_managed_trampoline_CardReader_iOS_ICTableContactSource_GetCell + 402

  

8 UIKit 0x3256da5b + 410

>9   UIKit                               0x32515e7d <redacted> + 1804

>10  UIKit                               0x32515699 <redacted> + 184

>11  UIKit                               0x3243bda3 <redacted> + 346

>12  QuartzCore                          0x320c2c6b <redacted> + 142

>13  QuartzCore                          0x320be47b <redacted> + 350

>14  QuartzCore                          0x320be30d <redacted> + 16

>15  QuartzCore                          0x320bdd1f <redacted> + 230

>16  QuartzCore                          0x320bdb2f <redacted> + 314

>17  QuartzCore                          0x32112825 <redacted> + 516

>18  IOMobileFramebuffer                 0x34d0876d <redacted> + 104

>19  IOKit                               0x309aaa75 IODispatchCalloutFromCFMessage + 248

>20  CoreFoundation                      0x2fc88e21 <redacted> + 136

>21  CoreFoundation                      0x2fc939df <redacted> + 34

>22  CoreFoundation                      0x2fc9397b <redacted> + 346

>23  CoreFoundation                      0x2fc9214f <redacted> + 1398

>24  CoreFoundation                      0x2fbfcc27 CFRunLoopRunSpecific + 522

>25  CoreFoundation                      0x2fbfca0b CFRunLoopRunInMode + 106

>26  GraphicsServices                    0x348ec283 GSEventRunModal + 138

>27  UIKit                               0x324a0049 UIApplicationMain + 1136

>28  CardReader_iOS                      0x00166e40 

wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string ___ intptr_intptr + 272

  

29 CardReader_iOS 0x00143244 MonoTouch_UIKit_UIApplication_Main_string___string_string + 300

>30  CardReader_iOS                      0x000aa148 CardReader_iOS_Application_Main_string__ + 172

>31  CardReader_iOS                      0x002740d0 

wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200

>32  CardReader_iOS                      0x003c1087 mono_jit_runtime_invoke + 1134

>33  CardReader_iOS                      0x003fbd2d mono_runtime_invoke + 88

>34  CardReader_iOS                      0x003ff8b5 mono_runtime_exec_main + 276

>35  CardReader_iOS                      0x003ff705 mono_runtime_run_main + 424

>36  CardReader_iOS                      0x003af6e1 mono_jit_exec + 48

>37  CardReader_iOS                      0x00432704 main + 2468

>38  libdyld.dylib                       0x3a4e5ab7 <redacted> + 2

>   Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.

这是我的代码:

此方法在服务器回调后执行我将数据从服务器填充到新列表

public void addContacts(){
        InvokeOnMainThread (delegate {
            try{
                tableContact.BeginUpdates();
                items.AddRange(itemsAdd);
                ICGlobal.contacts.AddRange(itemsAdd);

                tableContact.ReloadData();
                tableContact.SetNeedsDisplay();
                tableContact.EndUpdates();

            }catch(Exception e){
                Console.WriteLine(e.StackTrace);
            }
            ICLayoutMgr.Get().SetBusy(false);
            tableContact.ScrollEnabled = true;
        });
    }

这是自定义单元格类

public class ICTableContactCell : UITableViewCell
{
    ICContactTableItem item;
    ICContactCellView viewData;

    public ICTableContactCell (ICContactTableItem item,NSString cellId) : base(UITableViewCellStyle.Default, cellId )
    {
        ContentView.BackgroundColor = UIColor.White;
        this.item = item;
        viewData = new ICContactCellView (this.item);

        var view = new UIView (ContentView.Frame);
        view.BackgroundColor = UIColor.Gray;

        this.SelectionStyle = UITableViewCellSelectionStyle.Default;
        this.SelectedBackgroundView = view;

        ContentView.Add (viewData);
    }
    public override void LayoutSubviews ()
    {
        base.LayoutSubviews ();
        viewData.Frame = ContentView.Bounds;
        viewData.SetNeedsDisplay ();
    }
    public void UpdateCell (ICContactTableItem titem){
        this.item = titem;
        viewData.UpdateCell (titem);
    }
}
public class ICContactCellView:UIView{
    UILabel uiTitle;
    UILabel uiCompany;
    UIImageView imgSelected;
    UIImageView imgDetail;
    ICContactTableItem item;
    static UIImage arrow=UIImage.FromFile("btnArrow.png");
    static UIImage address=UIImage.FromFile("btnaddress.png");

    public ICContactCellView (ICContactTableItem item)
    {
        this.item = item;
        BackgroundColor = UIColor.White;
        float yOffset = 5f;
        UIColor otherColor = UIColor.Black;

        uiTitle = IOTM.GUI.CreateLabel ("TITLE", yOffset+10f, yOffset, 200f, 24f, otherColor, "Helvetica-Bold", 14f);
        uiCompany = IOTM.GUI.CreateLabel ("Comapany", yOffset+10f, yOffset + 16f, 200f, 24f, otherColor, "HelveticaNeue", 13f);
        imgSelected =new UIImageView(){
            Image = address,
            Frame = IOTM.GUI.CreateFrame( yOffset+235f, yOffset+5f, 30, 30)
        };
        imgDetail = new UIImageView () {
            Image = arrow,
            Frame = IOTM.GUI.CreateFrame (280f, yOffset + 15f, 10, 10)
        };
        Add (uiTitle);
        Add (uiCompany);
        Add (imgSelected);
        Add (imgDetail);

        UpdateCell (this.item);
    }
    public void UpdateCell (ICContactTableItem titem){
        this.item = titem;
        if (item.index % 2 == 0)
            BackgroundColor = ICGlobal.Gray;
        else {
            BackgroundColor = UIColor.White;
        }
        uiCompany.Text = "Company: " + item.enterprise;
        uiTitle.Text = item.firstName+" "+item.lastName;

        SetNeedsDisplay ();

    }
}

TableViewSource

public class ICTableContactSource : UITableViewSource
{
    public ICTableContactCell cell;
    private static ICLoadMoreCell loadMore;
    private ICContactTableItem itemC;

    protected List<ICContactTableItem> tableItems;
    protected string cellIdentifier;
    public UINavigationController ParentNavigation{ get; set; }

    public ICTableContactSource(List<ICContactTableItem> tl)
    {
        cellIdentifier = "contactCellID";
        tableItems = tl;
    }
    public override int RowsInSection(UITableView t, int i)
    {
        return tableItems.Count+1;
    }
    public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
    {
        if (indexPath.Row == tableItems.Count) {
            loadMore = tableView.DequeueReusableCell ("LoadingCell") as ICLoadMoreCell;
            if (loadMore == null) {
                loadMore = new ICLoadMoreCell (new NSString ("LoadingCell"));
            }
            loadMore.UpdateCell (null, 0);
            return loadMore;
        } else {

            cell = tableView.DequeueReusableCell (cellIdentifier) as ICTableContactCell;
            itemC = tableItems [indexPath.Row];
            if (cell == null) {
                itemC.index = indexPath.Row;
                cell = new ICTableContactCell (itemC, new NSString (cellIdentifier));
                cell.UpdateCell (itemC);

            } else {
                itemC.index = indexPath.Row;
                cell.UpdateCell (itemC);
            }
        }
        return cell as UITableViewCell;
    }
    public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
    {
        if (cell is ICLoadMoreCell) {
            ICGlobal.currentContactView.loadMore ();
        }
    }

0 个答案:

没有答案