Advertisement
uniique

Untitled

Mar 17th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Method call in my Controller
  2. [User getUserData:userDict:^(NSDictionary *user) {
  3.     [self.delegate loadUserData:user]; // the avatarImage should be already here
  4.     [self dismissViewControllerAnimated:YES completion:nil];
  5. }];
  6.  
  7. // User.m
  8. + (void)getUserData:(NSDictionary *)forUser:(void (^)(NSDictionary *users))block {
  9.    
  10.     NSMutableDictionary *userDic = [NSMutableDictionary dictionary];
  11.    
  12.     User *user = [[User alloc] initWithDictionary:forUser];
  13.     [userDic setObject:user forKey:@"user"];
  14.     block([NSDictionary dictionaryWithDictionary:userDic]);
  15. }
  16.  
  17. - (id)initWithDictionary:(NSDictionary *)aDictionary {
  18.     self = [super init];
  19.     if (!self) {
  20.         return nil;
  21.     }
  22.    
  23.     self.userAvatar = [UIImage imageNamed:@"placeholder.png"];
  24.    
  25.     [self getUserAvatar:[aDictionary objectForKey:@"user_avatar"]];
  26.     //_userAvatar = [self getUserAvatar:[aDictionary objectForKey:@"user_avatar"]];
  27.     self.userId = [aDictionary objectForKey:@"user_id"];
  28.     self.username = [aDictionary objectForKey:@"username"];
  29.     self.userEmail = [aDictionary objectForKey:@"user_email"];
  30.  
  31.     return self;
  32. }
  33.  
  34. - (void)getUserAvatar:(NSString *)avatarPath {
  35.     // don't need a __block var here
  36.     if ([avatarPath length] != 0) {
  37.         [[AFFnBAPIClient sharedClient] setDefaultHeader:@"Accept" value:@"image/png"];
  38.         [[AFFnBAPIClient sharedClient] getPath:FNB_DOWNLOAD_PATH parameters:[NSDictionary dictionaryWithObject:avatarPath forKey:@"avatar"] success:^(AFHTTPRequestOperation *operation, id image) {
  39.            
  40.             // self got a retain+1 while this was running.
  41.             self.userAvatar = image;
  42.            
  43.         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  44.             NSLog(@"Error");
  45.         }];
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement