gpt4 book ai didi

c# - Xamarin C# 一个 UITableView 中的两个 UITableViewCells

转载 作者:行者123 更新时间:2023-11-29 12:39:11 26 4
gpt4 key购买 nike

我想把两个不同的 UITableViewCell合二为一UITableView然而,当我尝试将数据加载到 TableSource 中时它只允许我发送一个 List<>一次。但是我需要两个 List<>用于显示我的两个单元格。我的 TableSource.cs 中的两个列表类是名为 instaData 和 faceData 的公共(public)变量。当我运行获取 instaData 和 faceData 的个人请求时,它可以完美运行。更好地展示然后解释:

请求 InstaData

var client = new RestClient ("https://api.instagram.com/v1");
client.ExecuteAsync (request, response => {
var rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);
InstagramObject.next_url = rootObject.pagination.next_url.ToString();
FLDTRequest.instagramDataCopy = rootObject.data;
table.InvokeOnMainThread (() => {
table.Source = new TableSource(stream);
((TableSource)table.Source).instaData = rootObject.data;
table.ReloadData ();
});
});

请求人脸数据

var client = new RestClient ("https://graph.facebook.com/");
client.ExecuteAsync (request, response => {
var rootObject = JsonConvert.DeserializeObject<Floadt.Core.Facebook.RootObject> (response.Content);
FLDTRequest.facebookDataCopy = rootObject.data;
table.InvokeOnMainThread (() => {
table.Source = new TableSource(stream);
((TableSource)table.Source).faceData = rootObject.data;
table.ReloadData ();
});
});

基本上,当我想获取两个数据时,我会调用这两个方法,但我通常会从最后调用的方法中得到一个错误,说该对象不是引用。例如:如果我最后调用 faceData 请求,它会说 Object is not a reference。这是我的 TableSource类:

public class TableSource : UITableViewSource 
{
StreamViewController controller;

public List<Datum> instaData { get; set; }
public List<string> twitData { get; set; }
public List<Floadt.Core.Facebook.Datum> faceData { get; set; }

public TableSource(StreamViewController stream)
{
controller = stream;
}

public override int RowsInSection (UITableView tableview, int section)
{
return faceData.Count;
}

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
if (indexPath.Row % 2 == 0) {
return 340;
} else {
return 436;
//return 210;
}
}

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
if (indexPath.Row % 2 == 0) {
NetworkCheck netCheck = new NetworkCheck ();
netCheck.runCheck ();
// bool log = netCheck.anyLoggedIn ();

if (tableView.ContentSize.Height - UIScreen.MainScreen.Bounds.Height <= tableView.ContentOffset.Y) {
BTProgressHUD.Show ("Getting more...");
FLDTRequest.getInstagramNextPage (tableView);
BTProgressHUD.Dismiss ();
}

var cell = tableView.DequeueReusableCell (InstagramCell.Key) as InstagramCell;

if (cell == null) {
cell = new InstagramCell ();
var views = NSBundle.MainBundle.LoadNib ("InstagramCell", cell, null);
cell = Runtime.GetNSObject (views.ValueAt (0)) as InstagramCell;
}

//Datum h = instaData [indexPath.Row/2];
//cell.BindData (h);

return cell;

} else {
NetworkCheck netCheck = new NetworkCheck ();
netCheck.runCheck ();
// bool log = netCheck.anyLoggedIn ();

if (tableView.ContentSize.Height - UIScreen.MainScreen.Bounds.Height <= tableView.ContentOffset.Y) {
BTProgressHUD.Show ("Getting more...");
FLDTRequest.getInstagramNextPage (tableView);
BTProgressHUD.Dismiss ();
}


var cell = tableView.DequeueReusableCell (FacebookCell.Key) as FacebookCell;

if (cell == null) {
cell = new FacebookCell ();
var views = NSBundle.MainBundle.LoadNib ("FacebookCell", cell, null);
cell = Runtime.GetNSObject (views.ValueAt (0)) as FacebookCell;
}

var fbPhotoCell = tableView.DequeueReusableCell (FacebookPhotoCell.Key) as FacebookPhotoCell;

if (fbPhotoCell == null) {
fbPhotoCell = new FacebookPhotoCell ();
var views = NSBundle.MainBundle.LoadNib ("FacebookPhotoCell", cell, null);
fbPhotoCell = Runtime.GetNSObject (views.ValueAt (0)) as FacebookPhotoCell;
}

Floadt.Core.Facebook.Datum f = faceData [indexPath.Row/2];

fbPhotoCell.BindData (f);
return fbPhotoCell;
}
}
}

最佳答案

看起来您正在尝试设置 table.Source 两次,每个 List 一次?您需要将您的列表合并到一个数据源中,并创建一个可以可视化两种数据类型的 UITableViewCell

关于c# - Xamarin C# 一个 UITableView 中的两个 UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25473370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com