方法甚至没有调用

时间:2014-08-25 13:33:38

标签: ios objective-c xcode

我有一个扩展UITableViewController的类并实现NSFetchedResultsControllerDelegate

我已经定义了(.h)方法:

-(void)populateDataWithCompletitionHandler:(void (^)(UIBackgroundFetchResult))completitionHandler usingCustomParser:(void(^)(NSArray* result))parser;

并实施了它:

-(void)populateDataWithCompletitionHandler:(void (^)(UIBackgroundFetchResult))completitionHandler usingCustomParser:(void (^)(NSArray *))parser
{
    __weak FetchedViewController *weakSelf = self;

   [self.webserviceCall setSuccessBlock:^(NSArray *result) {
       if (parser == nil) {
          // Parse success
       } else {
           parser(result);
       }
   }];

    [self.webserviceCall setFailureBlock:^{
        if (completitionHandler) {
            // Error management
        }
    }];

    [self.webserviceCall startAsynchronus];
}

WebserviceCall课程中我(在.h):

@property (copy, nonatomic) void(^successBlock)(NSArray *result);
@property (copy, nonatomic) void(^failureBlock)(void);

我注意到有时会调用startAsynchronus,有时则不会。我在它上面放了一个断点,在方法中放了另一个断点。

有时调用该方法(我的应用程序有效),有时在调用startAsynchronus之后调用。

startAsynchronus

-(void)startAsynchronus
{    
    [_sessionManager GET:_method parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        self.successBlock(responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"*** Request error %@, %@", error, [error localizedDescription]);
    }];

    //[task resume];
}

**我认为这是解决方案**

在我的viewWillAppear方法上查看我写道:

-(void)viewWillAppear:(BOOL)animated
{    
    [super viewWillAppear:animated];

    if ([[User sharedInstance] isLoggedIn]) {
        BOOL entityIsSync = [[NSUserDefaults standardUserDefaults] boolForKey:_item.entity];

        if (!entityIsSync) {
            self.webserviceCall = [[WebserviceCall alloc] initWithMethod:_item.method forEntity:_item.entity];
            [self populateDataWithCompletitionHandler:nil usingCustomParser:nil];
        }
    }
}

这一行必须在if语句之外:

self.webserviceCall = [[WebserviceCall alloc] initWithMethod:_item.method forEntity:_item.entity];

但我有另一个问题:为什么如果self.webservice调用为null,我将不会得到任何错误(在运行时)。

0 个答案:

没有答案