启动我的iOS Xamarin应用程序时出现异常

时间:2017-06-29 09:46:34

标签: c# ios xamarin xamarin.ios tableview

我遇到了iOS Xamarin App的问题。

每当我尝试使用Storyboard在我的一个视图中添加tableView时,我启动了我的应用程序,我总是遇到同样的错误。

  

Foundation.MonoTouchException:抛出Objective-C异常。名称:   NSInvalidArgumentException原因: - [TableSource initWithCoder:]:   无法识别的选择器发送到实例0x17d6a620

这是我的TableSource代码:

using Foundation;
using System;
using UIKit;

namespace SmartTransportNatif.iOS2
{
    public partial class TableSource : UITableViewSource
    {

        protected string[] tableItems;
        protected string cellIdentifier = "TableCell";
        HomeTableController home;

        public TableSource (IntPtr handle) : base (handle)
        {
        }

        public TableSource (string[] items, HomeTableController home)
        {
            this.home = home;
        }

        public override nint RowsInSection(UITableView tableview, nint section)
        {
            return tableItems.Length;
        }

        /// <summary>
        /// Called when a row is touched
        /// </summary>
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            UIAlertController okAlertController = UIAlertController.Create("Row Selected", tableItems[indexPath.Row], UIAlertControllerStyle.Alert);
            okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
            home.PresentViewController(okAlertController, true, null);

            tableView.DeselectRow(indexPath, true);
        }

        /// <summary>
        /// Called by the TableView to get the actual UITableViewCell to render for the particular row
        /// </summary>
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            // request a recycled cell to save memory
            UITableViewCell cell = tableView.DequeueReusableCell(cellIdentifier);
            // if there are no cells to reuse, create a new one
            if (cell == null)
                cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier);

            cell.TextLabel.Text = tableItems[indexPath.Row];

            return cell;
        }

    }
}

这是我的故事板:

Storyboard

以下是HomeTableController中我的Tableview的属性:

Properties

有人知道缺少什么或错了吗?

0 个答案:

没有答案
相关问题