簡體   English   中英

如何在 Rider 中為 Xamarin.ios 視圖設置屬性? (如何更新自動生成的 View.designer.cs?)

[英]How to set property for Xamarin.ios view in Rider? (How to update autogenerated View.designer.cs?)

如果我使用的是 Visual Studio for Mac,它在設計器中有這個字段。

它在 View.cs 文件中創建一個允許我綁定到它的屬性。

在此處輸入圖片說明

我在 xcode 中找到了一個類似的部分(這是 Rider 打開的部分),它只有這些選項。 沒有名稱字段。

在此處輸入圖片說明

此名稱字段不是按鈕標簽上顯示的內容。 我知道如何設置。

我更願意使用 Rider 而不是 Visual Studio for mac。 如果我必須不斷地來回跳躍,這顯然是一個問題。

編輯:據我所知,它似乎在編輯 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;
        }
    }
}
}

這是我使用設計器將 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 一樣好用,這是我使用的唯一其他產品。

騎士沒有一個特別設計.xib.storyboard UI文件。 我們(Rider 團隊)認為我們無法實現像原生 xcode 那樣好的(和實際的)UI 設計器。 因此,在 Rider 中使用 Xamarin macios UI 的主要場景 - 使用 xcode 界面構建器。

您可以查看有關插座生成的蘋果文檔: https : //developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/ConnectingObjectstoCode.html

這是如何使用默認設置在 xcode 11 中執行此操作的簡要說明。

  1. 將 UI 編輯器拆分為設計器和源代碼部分第1步

  2. Ctrl+單擊要綁定的控件並將其拖到代碼中。 重要說明:使用 .h 文件創建新的操作和出口,Rider 分析 .h 文件以構建公共 API 模型。 第2步

  3. 現在您可以輸入將創建綁定的控件的名稱。 您將在 objc 代碼中看到相應的出口。

也許它不是那么簡單,所以我將嘗試解釋它在內部是如何工作的。 Xamarin macios 項目是一個(幾乎)常規的 .NET C# 項目。 因此,為了允許您在 xcode 中編輯 UI,Rider(實際上是 VS)做了一些魔術。 它需要 .NET 項目和:

  1. 使用特定的設置和配置在obj\\xcode文件夾中創建相應的 xcodeproj(pbxproj 和朋友)項目。
  2. 復制所有內容,如視圖、plist 文件、圖像等。
  3. 查找所有ViewController類型。 對於它們中的每一個,Rider 生成帶有動作和出口的 objc 類。
  4. 打開 xcode 和生成的項目。

當您在該生成的項目中進行一些更改並返回 Rider 時,它會嘗試應用所有更改:

  1. 將所有更改的內容文件復制回 .NET 項目
  2. 更新設置
  3. 解析 objc 文件並為視圖控制器重新生成*.designer.cs文件。 對於所有這些文件,您將看到這個生成的標題(將來可以更改):
// 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 中打開項目時都會顯示它:

Rider 中的 xcode 控制台

而不是結論:Rider 的團隊試圖為 Xamarin 開發人員提供良好的體驗,甚至比 VS for Mac 更好。 因此,我們正在努力支持某些 Xamarin 部分(2020.1 中的 Xamarin Forms Hot Reload),因此請隨時在我們的公共問題跟蹤器中分享您的問題:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM