呼叫沙玛林

本文关键字:呼叫 | 更新日期: 2023-09-27 18:01:18

当用户使用XamarinUITableView拉到屏幕底部时,我试图加载旧的Instagram图片。然而,我似乎没有线索如何做到这一点。我让它在Objective-C中工作得很好,只是在c#中看起来不同。以下是我如何获得最初的帖子:

public void getInstagramFeed(UITableView table){
        IEnumerable<Account> accounts = AccountStore.Create ().FindAccountsForService ("Instagram");
        var enumerable = accounts as IList<Account> ?? accounts.ToList ();
        if (enumerable.Any ()) {
            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 => {
                table.InvokeOnMainThread (() => {
                RootObject rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);
                var dataSource = new ObservableDataSource<Datum> (rootObject.data);
                dataSource.Bind (table);
            });
        }); 
    }
}

下面是我的datasource的绑定方法:

public void Bind(Datum datum)
        {
            this.datum = datum;
            if (this.datum == null || this.datum.caption == null)
            {
                this.captionLabel.Text = "";
            }
            else
            {
                this.captionLabel.Text = datum.caption.text;
            }
            this.pictureImage.InvokeOnMainThread (() => this.pictureImage.SetImage (
                url: new NSUrl (datum.images.standard_resolution.url)
                    )
                );
                this.profileImage.InvokeOnMainThread (() => this.profileImage.SetImage (
                    url: new NSUrl (datum.user.profile_picture)
                    )
                );
            this.nameLabel.Text = this.datum.user == null ? "user is null" : datum.user.full_name;
        }

这是我的tableView类:

    public TableView ()
    {
    }
    public TableView (IntPtr handle) : base(handle)
    {
    }
    public UITableViewCell GetCell (Datum item)
    {
        var newCell = this.DequeueReusableCell(InstagramCell.Key) 
            as InstagramCell ?? InstagramCell.Create();
        newCell.Bind (item);
        return newCell;
    }
    public float GetHeightForRow (NSIndexPath indexPath)
    {
        return 340f;
    }

感谢之前所有的帮助,很抱歉长帖子:)

//PS这是我在OBJc中做的:

NSDictionary *page = instagramResponse[@"pagination"];
NSString *nextPage = page[@"next_url"];
[[InstagramClient sharedClient] getPath:[NSString stringWithFormat:@"%@",nextPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    instagramResponse = [responseObject mutableCopy];
    [instagramResponse addEntriesFromDictionary:responseObject];
    [instapics addObjectsFromArray:responseObject[@"data"]];
    [self updateArrays];
    [self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Failure: %@", error);

}];

//类InstagramClient:

public class RootObject
    {
        public Pagination pagination { get; set; }
        public Meta meta { get; set; }
        public List<Datum> data { get; set; }
    }
public class Datum
{
    public object attribution { get; set; }
    public List<string> tags { get; set; }
    public string type { get; set; }
    public object location { get; set; }
    public Comments comments { get; set; }
    public string filter { get; set; }
    public string created_time { get; set; }
    public string link { get; set; }
    public Likes likes { get; set; }
    public Images images { get; set; }
    public List<object> users_in_photo { get; set; }
    public Caption caption { get; set; }
    public bool user_has_liked { get; set; }
    public string id { get; set; }
    public User user { get; set; }
    public Videos videos { get; set; }
    public override string ToString()
    {
        if (user == null)
        {
            return "User is null";
        }
        return user.full_name;
    }
}
public class Videos
{
    public LowResolution2 low_resolution { get; set; }
    public StandardResolution2 standard_resolution { get; set; }
}
public class StandardResolution2
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}
public class LowResolution2
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}
public class User
{
    public string username { get; set; }
    public string website { get; set; }
    public string profile_picture { get; set; }
    public string full_name { get; set; }
    public string bio { get; set; }
    public string id { get; set; }
}
public class Caption
{
    public string created_time { get; set; }
    public string text { get; set; }
    public From from { get; set; }
    public string id { get; set; }
}
public class From
{
    public string username { get; set; }
    public string profile_picture { get; set; }
    public string id { get; set; }
    public string full_name { get; set; }
}
public class Images
{
    public LowResolution low_resolution { get; set; }
    public Thumbnail thumbnail { get; set; }
    public StandardResolution standard_resolution { get; set; }
}
public class StandardResolution
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}
public class Thumbnail
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}
public class LowResolution
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}
public class Likes
{
    public int count { get; set; }
    public List<Datum2> data { get; set; }
}
public class Datum2
{
    public string username { get; set; }
    public string profile_picture { get; set; }
    public string id { get; set; }
    public string full_name { get; set; }
}
public class Comments
{
    public int count { get; set; }
    public List<object> data { get; set; }
}
public class Meta
{
    public int code { get; set; }
}
public class Pagination
{
    public string next_url { get; set; }
    public string next_max_id { get; set; }
}

呼叫沙玛林

如果可能的话,我建议使用UiCollectionViewController。或者是现在的xamarin forms。使用UiCollectionViewController,你可以在用户向下滚动

时轻松加载更多项目