如何在Rider中为Xamarin.ios视图设置属性? (如何更新自动生成的View.designer.cs?)

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

如果我使用的是Visual Studio for Mac,则它在设计器中具有此字段。

它在View.cs文件中创建一个属性,允许我绑定到该属性。

enter image description here

我在xcode中找到了类似的部分(这是车手打开的部分),并且只有这些选项。没有名称字段。

enter image description here

此名称字段不是按钮标签上显示的内容。我知道该如何设置。

我更希望使用Rider而不是Mac的Visual Studio。如果我必须不断跳来跳去,这显然是个问题。

编辑:据我所知,似乎是在编辑View.designer.cs。

尽管有此评论。如何从Rider中进行编辑?

// WARNING
//
// This file has been generated automatically by Visual Studio from the 
outlets and
// actions declared in your storyboard file.
// Manual changes to this file will not be maintained.
//

这是新的MvvmCross项目在默认情况下的外观

using Foundation;
using System;
using System.CodeDom.Compiler;

namespace HelloCrossPlatform.iOS.Views
{
[Register ("FirstView")]
partial class FirstView
{
    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UILabel Label { get; set; }

    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UITextField TextField { get; set; }

    void ReleaseDesignerOutlets ()
    {
        if (Label != null) {
            Label.Dispose ();
            Label = null;
        }

        if (TextField != null) {
            TextField.Dispose ();
            TextField = null;
        }
    }
}
}

这是当我使用Designer将name属性添加到Visual Studio for Mac中的按钮时的外观

using Foundation;
using System;
using System.CodeDom.Compiler;

namespace HelloCrossPlatform.iOS.Views
{
[Register ("FirstView")]
partial class FirstView
{
    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UILabel Label { get; set; }

    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UIButton SayHelloButton { get; set; }

    [Outlet]
    [GeneratedCode ("iOS Designer", "1.0")]
    UIKit.UITextField TextField { get; set; }

    [Action ("UIButtonDZD114An_TouchUpInside:")]
    [GeneratedCode ("iOS Designer", "1.0")]
    partial void UIButtonDZD114An_TouchUpInside (UIKit.UIButton 
sender);

    void ReleaseDesignerOutlets ()
    {
        if (Label != null) {
            Label.Dispose ();
            Label = null;
        }

        if (SayHelloButton != null) {
            SayHelloButton.Dispose ();
            SayHelloButton = null;
        }

        if (TextField != null) {
            TextField.Dispose ();
            TextField = null;
        }
    }
}
}

骑手甚至是与Xamarin一起使用的好工具吗?我对他们甚至将其作为一种选择感到失望。真的质疑我对JetBrains的订阅。Vscode似乎和Webstorm一样好,Webstorm是我与他们合作的唯一其他产品。

xamarin xamarin.ios jetbrains-ide rider
1个回答
0
投票

[Rider没有.xib.storyboard UI文件的特殊设计器。我们(Rider团队)认为我们将无法实现与本机xcode一样好的(和实际的)UI设计器。因此,在Rider中使用Xamarin macios UI的主要方案-使用xcode接口构建器。

您可以查看有关网点生成的Apple文档:https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/ConnectingObjectstoCode.html

这是简短说明,如何使用默认设置在xcode 11中执行此操作。

  1. 将UI编辑器分为设计器和源代码部分Step 1

  2. Ctrl +单击要绑定的控件并将其拖动到代码中。 重要说明:使用.h文件创建新的动作和方法,Rider分析.h文件以构建公共API模型。Step 2

  3. 现在,您可以输入将要创建绑定的控件的名称。您将在objc代码中看到相应的出口。

也许不是那么简单,所以我将尝试解释其内部工作方式。Xamarin macios项目是一个(几乎)常规的.NET C#项目。因此,为了允许您在xcode中编辑UI,Rider(和VS实际上)做了一些魔术。它需要.NET项目和:

  1. 使用特定的设置和配置在obj\xcode文件夹中创建相应的xcodeproj项目(pbxproj和朋友)。>
  2. 复制所有内容,例如视图,plist文件,图像等。
  3. 查找所有ViewController类型。骑士会为他们每个人生成带有动作和出口的objc类。
  4. 将xcode和生成的项目打开到。
  5. 当您在生成的项目中进行了一些更改并返回到Rider后,它将尝试应用所有更改:

  1. 将所有更改的内容文件复制回.NET项目中
  2. 更新设置
  3. 解析objc文件并为视图控制器重新生成*.designer.cs文件。对于所有这些文件,您将看到此生成的标头(以后可以更改):
  4. // WARNING
    //
    // This file has been generated automatically by Rider IDE
    //   to store outlets and actions made in Xcode.
    // If it is removed, they will be lost.
    // Manual changes to this file may not be handled correctly.
    //
    

要控制xcode同步过程并查看发生了什么并查看发生了什么错误,可以使用特殊的Rider工具窗口:xcode console。每次您在xcode中打开一个项目时都会显示它:

xcode console in Rider

而不是结论:Rider的团队试图为Xamarin开发人员提供良好的体验,甚至比VS for Mac更好。因此,我们正在努力支持Xamarin的某些部件(2020.1中的Xamarin Forms Hot Reload),请随时在我们的公共问题跟踪器中分享您的麻烦:

https://youtrack.jetbrains.com/issues/RIDER?q=Technology:%20Xamarin%20

© www.soinside.com 2019 - 2024. All rights reserved.