xamarin.ios 屏幕不更新

问题描述 投票:0回答:1

我已经从我的 mac mini 设备的 Visual Studio(ios 13)创建了一个项目 xamarin.ios。 我已经删除了故事板文件。

我有 Main.cs、AppDelegate.cs、TableView.cs 和 TableSource.cs 文件。

主要.cs:

using System;
using UIKit;

namespace LabelWrap
{
    public class Application
    {
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            //UIApplication.Main(args, null, typeof(AppDelegate));


            try
            {
                UIApplication.Main(args, null, "AppDelegate");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
}

AppDelegate.cs:

using System;
using Foundation;
using UIKit;

namespace LabelWrap
{
    [Register("AppDelegate")]
    public class AppDelegate : UIApplicationDelegate
    {
        UIWindow window;

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            window.MakeKeyAndVisible();

            window.RootViewController = new TableView();
            
            return true;
        }
    }
}

TableSource.cs:

using System;
using Foundation;
using UIKit;

namespace LabelWrap
{
    public class TableSource : UITableViewSource
    {

        string[] TableItems;
        string CellIdentifier = "TableCell";

        public TableSource(string[] items)
        {
            TableItems = items;
        }

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

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
            string item = TableItems[indexPath.Row];

            //if there are no cells to reuse, create a new one
            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier);
            }

            cell.TextLabel.Text = item;

            return cell;
        }
    }
}

TableView.cs:

using Foundation;
using UIKit;

namespace LabelWrap
{
    public partial class TableView : UITableViewController
    {
        UITableView table;

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.Green;
            table = new UITableView(View.Bounds); // defaults to Plain style
            string[] tableItems = new string[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
            table.Source = new TableSource(tableItems);
            table.BackgroundColor = UIColor.Yellow;
            Add(table);
        }
    }  
}

我的项目运行成功,但当我打开应用程序时,Ios模拟器(ios 13)黑屏。 当我在代码中放置断点时,似乎一切都正确执行,但我在屏幕上看不到任何差异。

我是否遗漏了代码中的某些内容或者有错误?这样我在tableView中写的结果就可以在屏幕上看到了

c# ios xamarin xamarin.ios tableview
1个回答
0
投票

你的意思是你想要这个效果

  1. 打开VS for MAC并创建一个新项目(选择iOS应用程序
  2. 将您的代码移至此项目。
  3. 打开 info.plist 并删除
    Launch screen interface file base name
    的值,如 this
  4. 然后您可以选择是否删除故事板文件。
© www.soinside.com 2019 - 2024. All rights reserved.