我试图在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 (); }); }); });
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 ); }); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。