【发布时间】:2019-05-27 19:20:51
【问题描述】:
我尝试构建一个简单的 Xamarin Forms 应用程序,将联系人列表分组。在这种情况下,我只有两个联系人以保持轻松。在 iOS 模拟器或我的 iPhone 6s (iOS 12) 上启动应用程序时,会出现一条错误消息:
"{Foundation.MonoTouchException: 抛出 Objective-C 异常。名称: NSInvalidArgumentException 原因:*** -[NSPlaceholderString initWithUTF8String:]: NULL cString 本机堆栈跟踪: 0
CoreFoundation 0x00000001068e56fb __exceptionPrepr…}"
c#
namespace Lists{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
listView.ItemsSource = new List<ContactGroup> {
new ContactGroup("P", "P")
{
new Contact { Name = "Peter Parker", Status = "Nice to meet you!" }
},
new ContactGroup("J", "J")
{
new Contact { Name = "John Smith", Status = "Hey, let's talk!" }
}
};
}
}
public class Contact
{
public string Name { get; set; }
public string Status { get; set; }
}
public class ContactGroup : List<Contact>
{
public string Title { get; set; }
public string ShortTitle { get; set; }
public ContactGroup(string title, string shortTitle)
{
Title = title;
ShortTitle = shortTitle;
}
}
}
xaml
<?xml version="1.0" encoding="utf-8"?>
<ContentPage
Padding="0, 20, 0, 0"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Lists" x:Class="Lists.MainPage">
<ListView x:Name="listView"
IsGroupingEnabled="true"
GroupDisplayBinding="{Binding Title}"
GroupShortNameBinding="{Binding shortTitle}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding Status}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
【问题讨论】:
标签: c# xaml xamarin xamarin.ios