我有一个标题UIView,我试图将JSON数据加载到,但是根本没有显示任何信息,如下所示:
以下是我加载标题视图的方法:
- (ForeignInstagramViewHeader *)header {
if (!_header) {
_header = [[ForeignInstagramViewHeader alloc] initWithFrame:CGRectMake(0, 0, 320, 150) withUserData:self.instaUser];
NSString *userID = self.instagramData[@"user"][@"id"];
[self getInstaDataWithUserID:userID];
_header.instaUser = self.instaUser;
}
return _header;
}
以下是获取Instagram数据的方法:
- (void)getInstaDataWithUserID:(NSString *)user {
NSString *path = [NSString stringWithFormat:@"users/%@", user];
[[InstagramClient sharedClient] getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",responseObject);
self.instaUser = [[InstagramUser alloc] init];
[self.instaUser setBio:responseObject[@"data"][@"bio"]];
self.instaUser.followed_by = responseObject[@"data"][@"counts"][@"followed_by"];
self.instaUser.follows = responseObject[@"data"][@"counts"][@"follows"];
self.instaUser.media = responseObject[@"data"][@"counts"][@"media"];
self.instaUser.full_name = responseObject[@"data"][@"full_name"];
self.instaUser.idvalue = responseObject[@"data"][@"id"];
self.instaUser.profile_picture = responseObject[@"data"][@"profile_picture"];
self.instaUser.username = responseObject[@"data"][@"username"];
self.instaUser.website = responseObject[@"data"][@"website"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
这是我的标题View Class.h:
@interface ForeignInstagramViewHeader : UIView
@property (nonatomic, strong) UIImageView *profilePic;
@property (nonatomic, strong) UILabel * nameString;
@property (nonatomic, strong) UILabel * postCount;
@property (nonatomic, strong) UILabel * postString;
@property (nonatomic, strong) UILabel * followerCount;
@property (nonatomic, strong) UILabel * followerString;
@property (nonatomic, strong) UILabel * followingCount;
@property (nonatomic, strong) UILabel * followingString;
@property (nonatomic, strong) UILabel * bioString;
@property (nonatomic, strong) UILabel * websiteString;
@property InstagramUser *instaUser;
- (id)initWithFrame:(CGRect)frame withUserData:(InstagramUser *)instagram;
@end
答案 0 :(得分:0)
在ForeignInstagramViewHeader
类中添加一个方法来更新用户详细信息,例如
- (void)updateWithUserDetails:(InstagramUser *)user {
self.instaUser = user;
// set values from user to lable's and other UI elements.
}
和标题方法将是
- (ForeignInstagramViewHeader *)header {
if (!_header) {
_header = [[ForeignInstagramViewHeader alloc] initWithFrame:CGRectMake(0, 0, 320, 150) withUserData:self.instaUser];
}
return _header;
}
并在getInstaDataWithUserID:
方法中,
- (void)getInstaDataWithUserID:(NSString *)user {
NSString *path = [NSString stringWithFormat:@"users/%@", user];
[[InstagramClient sharedClient] getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",responseObject);
self.instaUser = [[InstagramUser alloc] init];
[self.instaUser setBio:responseObject[@"data"][@"bio"]];
self.instaUser.followed_by = responseObject[@"data"][@"counts"][@"followed_by"];
self.instaUser.follows = responseObject[@"data"][@"counts"][@"follows"];
self.instaUser.media = responseObject[@"data"][@"counts"][@"media"];
self.instaUser.full_name = responseObject[@"data"][@"full_name"];
self.instaUser.idvalue = responseObject[@"data"][@"id"];
self.instaUser.profile_picture = responseObject[@"data"][@"profile_picture"];
self.instaUser.username = responseObject[@"data"][@"username"];
self.instaUser.website = responseObject[@"data"][@"website"];
//UPDATE
dispatch_async(dispatch_get_main_queue(), ^{
[[self header] updateWithUserDetails:self.instaUser];
});
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}