c# - 如何将数据从 View Controller 发送到 View Controller Xamarin iOS(C#)

标签 c# ios xamarin xamarin.ios

我有一些按钮(名称 - 'button_arrow_product002')的 View ,我想发送数据 wen 按钮 'button_arrow_product002' 被点击 我在 ViewController 中的代码名称为“HarachieRolliController”:

String title = json[1]["post_title"].ToString();
button_arrow_product002.TouchUpInside += (o,s) => {         
        DetailTovarProsmotr x;
        x.HendlerButtonClicked(title);
        Console.Out.WriteLine("Нажали кнопку перехода в детальный просмотр!!!!");
};

代码 ViewCotroller 处理按钮点击的内容:

namespace murakami_kiev
{
partial class DetailTovarProsmotr : UIViewController
{

    public DetailTovarProsmotr (IntPtr handle) : base (handle)
    {
    }
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

    }
    public void HendlerButtonClicked(String json){
        titleproduct.Text = json;

    }
}
}

这段代码有错误

'Use of unassigned local variable'

当我创建“new DetailTovarProsmotr()”时,我肯定有一些参数,但我不知道那些。

更新

我正在创建第二个构造函数并接收 String 类型变量。但是我有错误“对象引用未设置为对象的实例”。帮我解决我的问题。我的截图:enter image description here

最佳答案

作为一个夏天。所有异常的根源是您试图访问/设置未实例化类的成员。

正如我在评论中提到的,您需要创建一个实例,然后才能修改它。

要解决您的第一个问题,您需要将 DetailTovarProsmotr x; 更改为 DetailTovarProsmotr x = new DetailTovarProsmotr(); 并在 DetailTovarProsmotr Controller 中创建标准构造函数。

这同样基本上适用于您的第二个问题与 titleproduct。 titleproduct 属于 UITextView 类型,因此您需要创建一个实例,然后您可以通过设置 text 属性对其进行操作。在 titleproduct.Text = title2; 之前添加 titleproduct = new UITextView(new CGRect(10,10,120,30)); 将解决您的 NullReferenceException。

关于c# - 如何将数据从 View Controller 发送到 View Controller Xamarin iOS(C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34590155/

相关文章:

c# - 在 iOS 13 中访问(File.Copy)共享文件失败

c# - 调试 WPF 时遇到问题

c# - 结构与类,字符串和列表?

ios - UITableView 滚动条随着用户滚动而改变大小

ios - 应用程序内购买

ios - UICollectionView 重复和乱序显示项目

c# - 使用 Winform C# ,删除 exe 所在的文件夹

c# - 如何使用 C# 复制 Azure Data Lake Store 中的文件

ios - ECSlidingViewController 在设备方向变为横向时隐藏

c# - 如何调试 "cannot convert to system.collections.generic.list"错误