我想对从 JSON 响应中返回的单元格进行样式设置。我可以遍历元素,但是一旦我尝试设置它们的样式,就会出现以下错误。
我错过了什么?
! - 错误
收藏已修改;枚举操作可能无法执行。
! - 代码
string responseString = string.Empty;
Uri uri = new Uri ("http://myhost/sample.json");
HttpWebRequest request = new HttpWebRequest (uri);
request.Method = "GET";
HttpWebResponse response = request.GetResponse () as HttpWebResponse;
var obj = JsonValue.Load (new StreamReader (response.GetResponseStream())) as JsonObject;
if (obj != null) {
var root = JsonElement.FromJson (obj);
var jsonSection = root["section-1"] as Section;
UILabel headerLabel = new UILabel();
headerLabel.BackgroundColor = UIColor.White;
headerLabel.Opaque = false;
headerLabel.TextColor = UIColor.Blue;
headerLabel.HighlightedTextColor = UIColor.White;
headerLabel.Font = UIFont.BoldSystemFontOfSize (22);
headerLabel.Frame = new RectangleF(8,0,200,60);
headerLabel.Text = jsonSection.Caption;
jsonSection.HeaderView = headerLabel;
Console.WriteLine("before");
foreach (var elmList in jsonSection)
{
Console.WriteLine("test");
var element = new StyledStringElement(elmList.ToString())
{
TextColor = UIColor.Red,
BackgroundColor = UIColor.Brown,
Accessory = UITableViewCellAccessory.DisclosureIndicator
};
jsonSection.Elements.Add(element);
}
var dvc = new DialogViewController (root, true);
navigation.PushViewController (dvc, true);
}
response.Close ();