加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在RestSharp中显示下一组图像

发布时间:2020-12-15 22:05:00 所属栏目:百科 来源:网络整理
导读:我试图在Xamarin中创建一个无限的桌面作为Instagram客户端.然而,当我滚动到屏幕的底部时,它会加载相同的第二页图像.它正常加载第一页然后正常加载第二页,但是当我尝试加载第三页时,它再次加载第二页.我该如何解决这个问题?这是我试图加载它的方式: Account
我试图在Xamarin中创建一个无限的桌面作为Instagram客户端.然而,当我滚动到屏幕的底部时,它会加载相同的第二页图像.它正常加载第一页然后正常加载第二页,但是当我尝试加载第三页时,它再次加载第二页.我该如何解决这个问题?这是我试图加载它的方式:

Account instagram = enumerable.First ();
var instagramAccessToken = instagram.Properties ["access_token"].ToString ();

var request = new RestRequest { RootElement = "data",Resource = "/users/self/feed" };
request.AddParameter ("access_token",instagramAccessToken);

var client = new RestClient ("https://api.instagram.com/v1");
client.ExecuteAsync (request,response => {
    var rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);

    string nextURL = rootObject.pagination.next_url;
    //// Create Next Client
    var requestBack = new RestRequest ();
    var clientBack = new RestClient (nextURL);

    // GET Next Response
    clientBack.ExecuteAsync (requestBack,responseBack => {
        var rootObjectBack = JsonConvert.DeserializeObject<RootObject> (responseBack.Content);
        table.InvokeOnMainThread (() => {
            // Create list that contains newly attained JSON
            List<Datum> instagramData = rootObjectBack.data;
            // Create dummy list for other values
            List<Datum> sloppy = null;
            ((TableSource<Datum>)table.Source).instaData.AddRange (instagramData);
            table.ReloadData ();
            });
        });
    });

这是我检测到用户位于TableView底部的地方

public override UITableViewCell GetCell (UITableView tableView,MonoTouch.Foundation.NSIndexPath indexPath)
    {

        NetworkCheck netCheck = new NetworkCheck ();
        netCheck.runCheck ();
        bool log = netCheck.anyLoggedIn ();

        if (tableView.ContentSize.Height - UIScreen.MainScreen.Bounds.Height <= tableView.ContentOffset.Y) {
            // this is the last row in the last section
            Console.WriteLine ("~~~Bottom~~~");
            FLDTRequest fldt = new FLDTRequest ();
            fldt.getPastInstagramFeed (tableView);
        }
        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];
        cell.BindData(h);

        return cell;
    }

解决方法

将回调放在一个单独的递归函数中,只要有一个nexturl就会一直调用自己.不知道instagram API,但这样的东西应该工作.

在viewdidload或其他东西中运行它(不是每次到达底部但是一次)

nextUrl = null;

Account instagram = enumerable.First ();
var instagramAccessToken = instagram.Properties ["access_token"].ToString ();

var request = new RestRequest { RootElement = "data",resp =>
    {
        PageRetrievedCallback(resp );
    });

回调函数

将nextUrl存储为类值

string nextUrl = null;

public void PageRetrievedCallback(RestResponse response)
{
    var rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);
    nextURL = rootObject.pagination.next_url;

    table.InvokeOnMainThread (() => {
            // Create list that contains newly attained JSON
            List<Datum> instagramData = rootObject.data;
            // Create dummy list for other values
            List<Datum> sloppy = null;
            ((TableSource<Datum>)table.Source).instaData.AddRange (instagramData);
            table.ReloadData ();
         });
}

当你检测到底部加载下一页时运行这个:

if ( ! string.IsNullOrEmpty (nextURL) ) 
{

    var requestBack = new RestRequest ();
    var clientBack = new RestClient (nextURL);
    clientBack.ExecuteAsync (requestBack,resp =>
    {
        PageRetrievedCallback(resp );
    });
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读