我在IOS上使用slideoverkit幻灯片菜单时遇到问题。菜单显示时,它不显示标签文本,仅显示为:Slide Menu not working
它在android上完美运行。这是我的实现方式:
主详细页代码(.xaml):
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
public class JsonToPojo {
public static void main(String[] args) {
String json = getJson();
GsonBuilder gsonBuilder = new GsonBuilder();
JsonDeserializer<Example> deserializer = new JsonDeserializer<Example>() {
@Override
public Example deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
Example example = new Example();
JsonObject jsonObject = json.getAsJsonObject();
example.setProject(jsonObject.getAsJsonObject("properties").getAsJsonObject("project")
.getAsJsonArray("projectList").get(0).getAsString());
JsonObject subElementProperties = jsonObject.getAsJsonObject("properties").getAsJsonObject("students")
.getAsJsonObject("subelements").getAsJsonObject("properties");
JsonArray idExamples = subElementProperties.getAsJsonObject("id").getAsJsonArray("examples");
JsonArray depExamples = subElementProperties.getAsJsonObject("dep").getAsJsonArray("examples");
List<Student> students = new ArrayList<Student>();
for (int i = 0; i < idExamples.size(); i++) {
Student student = new Student();
student.setId(idExamples.get(i).getAsString());
student.setDep(depExamples.get(i).getAsString());
students.add(student);
}
example.setStudents(students);
return example;
}
};
gsonBuilder.registerTypeAdapter(Example.class, deserializer);
Gson customGson = gsonBuilder.create();
Example customObject = customGson.fromJson(json, Example.class);
System.out.println(customObject.getStudents() + ", " + customObject.getProject());
}
private static String getJson() {
return "{ "
+ " \"$id\": \"students.json\", "
+ " \"type\": \"object\", "
+ " \"properties\": { "
+ " \"project\": { "
+ " \"$id\": \"project\", "
+ " \"projectList\": [ "
+ " \"ABC\" "
+ " ] "
+ " }, "
+ " \"students\": { "
+ " \"$id\": \"subproject\", "
+ " \"type\": \"array\", "
+ " \"subelements\": { "
+ " \"properties\": { "
+ " \"id\": { "
+ " \"$id\": \"id\", "
+ " \"examples\": [ "
+ " \"Y\" "
+ " ] "
+ " }, "
+ " \"dep\": { "
+ " \"$id\": \"dep\", "
+ " \"examples\": [ "
+ " \"X\" "
+ " ] "
+ " } "
+ " }, "
+ " \"required\": [ "
+ " \"id\", "
+ " \"dep\" "
+ " ] "
+ " } "
+ " } "
+ " }, "
+ " \"required\": [ "
+ " \"project\" "
+ " ] "
+ "} ";
}
}
这是我用于IOS的自定义渲染器(取自github slideoverkit):
<t:SlideMenuView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:menutest"
x:Class="menutest.MainPage"
BackgroundColor="White">
<StackLayout>
<StackLayout Orientation="Vertical" Spacing="0" >
<Frame BackgroundColor="White" HeightRequest="50" HasShadow="False" >
<Label TextColor="Black" Text="johnhastings@hotmail.com" VerticalOptions="End" FontSize="Medium" >
</Label>
</Frame>
<BoxView HeightRequest="10" Color="Black"></BoxView>
<Frame x:Name="client" BackgroundColor="White" HasShadow="False" >
<Label TextColor="Black" Text="CLIENTS ➤" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Frame>
<BoxView HeightRequest="2" Color="Gray"/>
<Frame BackgroundColor="White" HasShadow="False">
<Label TextColor="Black" Text="WIZARD ➤" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Frame>
<BoxView HeightRequest="2" Color="Gray" />
<Frame BackgroundColor="White" HasShadow="False">
<Label TextColor="Black" Text="SETTINGS ➤" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Frame>
<BoxView HeightRequest="2" Color="Gray"/>
<Frame BackgroundColor="White" HasShadow="False">
<Label TextColor="Black" Text="GUIDES AND TEMPLATES ➤" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Frame>
<BoxView HeightRequest="2" Color="Gray"/>
<Frame BackgroundColor="White" HasShadow="False">
<Label TextColor="Black" Text="HELP ➤" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Frame>
<BoxView HeightRequest="2" Color="Gray"/>
<Frame BackgroundColor="White" HasShadow="False">
<Label TextColor="Black" Text="LOGOUT ➤" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Frame>
</StackLayout>
</StackLayout>
<t:SlideMenuView/>
代码没有任何问题。我也尝试了列表视图,但视单元格不显示标签文本,其他内容(如颜色)也正在显示。
谢谢。