自分のユーザーが自分のプロフィール(ViewController)で写真をアップロードしたり受けたりできます。つまり、写真が保存されたら、保存した直後に最新の写真でimageViewを更新します。そのためには、NSString(secondLink)を更新する必要があります。理論的には、以下のコードがうまくいくと思います。メソッドを成功させると、userpicUpdatedメソッドをトリガーします(メソッド "サーバーからの情報の再取得")。つまり、何らかの理由で、以下のuserpicUpdatedメソッドは、更新されたデータではなく、field_photo_path内の古いデータを取得するだけです。これをどうすれば解決できますか?通知がトリガーされたときにNSStringが更新されない
AppDelegate.m
#import "DIOSSession.h"
@interface AppDelegate()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[DIOSSession setupDios];
}
ViewController.m
- (void)userpicUpdated:(NSNotification *)note {
}
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userpicUpdated:)
name:@"userpicUpdated" object:nil];
}
- (IBAction)savePhotoButton:(id)sender {
[DIOSUser
userUpdate:userData
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */
NSLog(@"User data updated!");
self.activityInd.hidden = YES;
[self.activityInd stopAnimating];
[DIOSUser
userGet:userData
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */
[[NSNotificationCenter defaultCenter] postNotificationName:@"userpicUpdated" object:nil];
NSDictionary *thisUser = userData;
NSLog(@"USER DATA GOTTEN %@", thisUser);
NSString *imageUpdate = thisUser[@"field_photo_path"][@"und"][0][@"value"];
NSLog(@"IMAGE STRING %@", imageUpdate);
NSURL *imageUrl = [NSURL URLWithString:imageUpdate];
[self.imageView setImageWithURL:imageUrl];
NSLog(@"IMAGE URL %@", imageUrl);
}
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */
NSLog(@"User data failed to update!");
}
];
}
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */
NSLog(@"User data failed to update!");
}
];
}
サーバーからユーザーデータを再フェッチするコードはどこですか?ここのコードは、以前に取得した辞書を参照するように見えます。 – Paulw11
あなたが言っていることは、ネットワーク操作の後に変更された値を 'user [@" field_photo_path "] [@" und "[0] [@" safe_value "]'それが何であるかを見ずに助けて、それを変更しようとするいくつかのコードを見ていますか? – danh
@ Paulw11ユーザーデータは、アプリケーション起動時(DIOSSession)にAppDelegateで取得されます。上記の編集を参照してください。 – Brittany