Ios 触发通知时NSString未更新

Ios 触发通知时NSString未更新,ios,objective-c,Ios,Objective C,我的用户可以在他们的个人资料(ViewController)上上传和/或拍照。也就是说,照片保存后,我希望imageView在保存后立即更新为最新的照片。为此,我需要刷新NSString(secondLink)。理论上,我认为下面的代码可以工作——例如,成功保存后触发方法userpicUpdated(方法“重新获取”服务器上的信息)。也就是说,出于某种原因,下面的userpicUpdated方法只是提取字段\照片\路径中的旧数据,而不是更新的数据。我怎样才能解决这个问题 AppDelegate.

我的用户可以在他们的个人资料(ViewController)上上传和/或拍照。也就是说,照片保存后,我希望imageView在保存后立即更新为最新的照片。为此,我需要刷新NSString(secondLink)。理论上,我认为下面的代码可以工作——例如,成功保存后触发方法userpicUpdated(方法“重新获取”服务器上的信息)。也就是说,出于某种原因,下面的userpicUpdated方法只是提取字段\照片\路径中的旧数据,而不是更新的数据。我怎样才能解决这个问题

AppDelegate.m

#import "DIOSSession.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        [DIOSSession setupDios];

    }
 - (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!");
         }
         ];

        }
ViewController.m

#import "DIOSSession.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        [DIOSSession setupDios];

    }
 - (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!");
         }
         ];

        }
DIOSUser-userUpdate:
不会重新加载用户信息,因此在更新成功时需要调用
DIOSUser-userGet:
。在
userGet:
success上,您可以保存返回的用户数据并通过启动
NSNotificationCenter
更新
UIImage


如果成功更新
ui图像
,则无需使用
NSNotificationCenter
。还值得检查
imageView
是否仍然可以访问(iOS是否从内存中释放了它?)以避免崩溃

- (IBAction)savePhotoButton:(id)sender {
    [DIOSUser userUpdate:userData
                 success:^(AFHTTPRequestOperation *op, id response) {
                      NSLog(@"User data updated!");
                      self.activityInd.hidden = YES;
                      [self.activityInd stopAnimating];

                      [DIOSUser userGet:userData
                                success:^(AFHTTPRequestOperation *op, id response) {
                                    [[DIOSSession sharedSession] user] = userData;
                                    NSLog(@"USER DATA GOTTEN %@", userData);

                                    NSString *imageUpdate = userData[@"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) {
                                     NSLog(@"User data failed to update!");
                                 }];
                  }
                  failure:^(AFHTTPRequestOperation *op, NSError *err) {
                       NSLog(@"User data failed to update!");
                  }];

}
您最初在哪里设置
[[DIOSSession sharedSession]用户]
,或者您第一次在哪里设置
用户数据。你能给我看一下密码吗


从源代码中,我看不到
userData
userGet:
上自动更新。我原以为您需要将
userData
设置为
response
中返回的数据。你能做一个
NSLog(@“Response%@”,Response)
并查看是否与当前的
用户数据

从服务器重新获取用户数据的代码在哪里?这里的代码似乎引用了以前获取的字典。我想你是说,你希望
用户[@“field\u photo\u path”[@“und”][0][@“safe\u value”]
在某些网络操作后包含一个更改的值,但是如果没有看到它是什么,看到一些试图更改它的代码,谁又能帮上忙呢,etc?@Paulw11当应用程序启动时,用户数据在AppDelegate中获取(DIOSSession)。请参阅上面的编辑。那么,您不需要执行一些任务来刷新用户吗?如果您正在获取旧数据,则有些事情您没有做,但它将成为
DIOSUser
objectAhhh的一部分。好的,请参见编辑。现在我只是不确定我应该在我的通知方法中添加什么?更新图像字符串起作用,并返回更新后的值…但当我更改屏幕并返回时,图像将返回到旧值。我在userGet success上更新它-我缺少什么?@Brittany我从未使用过Drupal或它的SDK,因此只能快速查看源代码。根据您的编辑,您的
UIViewController
似乎在从
[[DIOSSession sharedSession]user]
中存储的值变为活动状态时设置
UIImage
,但是
sharedSession
上的
user
仍然包含旧数据,因为您仅在本地使用了响应。查看我编辑的答案,其中不是本地声明的
thisUser
,而是将其设置为
sharedSession
user