首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误CS0246:在执行CI构建时找不到类型或命名空间名称'UIKit‘

错误CS0246:在执行CI构建时找不到类型或命名空间名称'UIKit‘
EN

Stack Overflow用户
提问于 2022-04-02 14:42:49
回答 1查看 251关注 0票数 0

UIKit将在我的CI构建中构建在我的解决方案中的IOS项目中,但不会构建在我这里提到的普通项目中,在这里输入图像描述

这给了我上面提到的错误。知道原因吗。我需要它在我的ipone上做警报,因为App.Current.MainPage.DisplayAlert和PopupNavigation.Instance.PushAsync(新的PopupPage());使用Rg.Plugins.Popup.Pages.PopupPage不起作用,但是我知道UIKit中的警报是在我的另一个IOS应用程序上工作的。

哦,顺便说一句,这是在本地建立的,只是不是在我的CI构建上。

这是我的CI构建的yaml,非常基本

步骤:任务: XamariniOS@2 displayName:‘构建解决方案’输入: solutionFile: MileageManagerForms.sln配置:‘Ad’干净: true workingDirectory: MileageManagerForms/MileageManagerForms.iOS

EN

回答 1

Stack Overflow用户

发布于 2022-04-04 09:30:46

确保正确添加了UIKit程序集引用。

根据微软文档

找不到程序中使用的类型或命名空间。您可能忘记引用(-reference)包含类型的程序集,或者您可能没有使用指令添加所需的程序集。或者,您要引用的程序集可能有问题。

使用UIAlertControllerStyle指示对display.These警报类型的警报类型如下:

代码语言:javascript
运行
复制
•   UIAlertControllerStyleActionSheet
•   UIAlertControllerStyleAlert

显示简单警报的代码如下所示:

代码语言:javascript
运行
复制
okayButton.TouchUpInside += (sender, e) => {

    //Create Alert
    var okAlertController = UIAlertController.Create ("Title", "The message", UIAlertControllerStyle.Alert);

    //Add Action
    okAlertController.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Default, null));

    // Present Alert
    PresentViewController (okAlertController, true, null);
};

参考链接:https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/alerts

更新:有一个解决办法,使用依赖服务设置iOS项目的警报。

1.在共享包中创建一个接口。

代码语言:javascript
运行
复制
public interface IMessage
{
    void LongAlert(string message);
    void ShortAlert(string message);
}

2.在iOS项目中,我们应该实施它。

代码语言:javascript
运行
复制
[assembly: Xamarin.Forms.Dependency(typeof(MessageIOS))]
namespace Your.Namespace
{
      public class MessageIOS : IMessage
    {
        const double LONG_DELAY = 3.5;
        const double SHORT_DELAY = 2.0;

        NSTimer alertDelay;
        UIAlertController alert;

        public void LongAlert(string message)
       {
           ShowAlert(message, LONG_DELAY);
       }
        public void ShortAlert(string message)
        {
           ShowAlert(message, SHORT_DELAY);
        }

        void ShowAlert(string message, double seconds)
       {
           alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
          {
               dismissMessage();
          });
           alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
        UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
    }

    void dismissMessage()
    {
        if (alert != null)
        {
            alert.DismissViewController(true, null);
        }
        if (alertDelay != null)
        {
            alertDelay.Dispose();
        }
    }
}
}

您可以在我们项目的任何地方获得警报服务。

代码语言:javascript
运行
复制
DependencyService.Get<IMessage>().ShortAlert(string message); 
DependencyService.Get<IMessage>().LongAlert(string message);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71718489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档