Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Method call in my Controller
- [User getUserData:userDict:^(NSDictionary *user) {
- [self.delegate loadUserData:user]; // the avatarImage should be already here
- [self dismissViewControllerAnimated:YES completion:nil];
- }];
- // User.m
- + (void)getUserData:(NSDictionary *)forUser:(void (^)(NSDictionary *users))block {
- NSMutableDictionary *userDic = [NSMutableDictionary dictionary];
- User *user = [[User alloc] initWithDictionary:forUser];
- [userDic setObject:user forKey:@"user"];
- block([NSDictionary dictionaryWithDictionary:userDic]);
- }
- - (id)initWithDictionary:(NSDictionary *)aDictionary {
- self = [super init];
- if (!self) {
- return nil;
- }
- self.userAvatar = [UIImage imageNamed:@"placeholder.png"];
- [self getUserAvatar:[aDictionary objectForKey:@"user_avatar"]];
- //_userAvatar = [self getUserAvatar:[aDictionary objectForKey:@"user_avatar"]];
- self.userId = [aDictionary objectForKey:@"user_id"];
- self.username = [aDictionary objectForKey:@"username"];
- self.userEmail = [aDictionary objectForKey:@"user_email"];
- return self;
- }
- - (void)getUserAvatar:(NSString *)avatarPath {
- // don't need a __block var here
- if ([avatarPath length] != 0) {
- [[AFFnBAPIClient sharedClient] setDefaultHeader:@"Accept" value:@"image/png"];
- [[AFFnBAPIClient sharedClient] getPath:FNB_DOWNLOAD_PATH parameters:[NSDictionary dictionaryWithObject:avatarPath forKey:@"avatar"] success:^(AFHTTPRequestOperation *operation, id image) {
- // self got a retain+1 while this was running.
- self.userAvatar = image;
- } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
- NSLog(@"Error");
- }];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement