Objective c GridView中的Xcode UILabel仅每隔加载一次更新

Objective c GridView中的Xcode UILabel仅每隔加载一次更新,objective-c,xcode,Objective C,Xcode,这是我见过的最奇怪的行为,我有一些简单的代码,我在许多其他情况下使用过,但出于某种原因,它只是在偶数次尝试时更新 你选择一种类型,它设置,然后文本清除,然后设置,我无法理解: 我正在使用以下代码: - (void) CalculateDueDate { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; NSDictionary *params = [NSDiction

这是我见过的最奇怪的行为,我有一些简单的代码,我在许多其他情况下使用过,但出于某种原因,它只是在偶数次尝试时更新

你选择一种类型,它设置,然后文本清除,然后设置,我无法理解:

我正在使用以下代码:

- (void) CalculateDueDate
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];


NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        NewBid.BidJobTypeId, @"typeId",  nil];

[appDelegate.globalObjectManager getObjectsAtPath:@"/api/bid/GetDueDate" parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    dueDate = [mappingResult.array objectAtIndex:0];
    NewBid.RequestDueDate = [CommonUtils GetDateFromString:dueDate.Description];


    // need to debug, loading twice and inconsistent
    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:4 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];

    //[self.tableView reloadData];

    // need more debug , not loading, flashing once blank once good, firing events multiple times, something wrong, maybe claculate inside of cellforindexpath not good idea
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Failed");
}];
}

下面是我拍摄的一段视频:

我想做的是,当选择作业类型时,它应该计算一个异步日期,然后在网格中设置标签,我已经做了数百次了,但由于某种原因,这个网格不工作,有什么想法吗

这里还有我从选择器编写的自定义委托

- (void) madeGenericSelection:(GenericSelectorViewController *)viewController didChooseItem:(GenericItem *)item selectedRow:(NSNumber *)row
{


switch ([row intValue]) {
    case 1:
        NewBid.BidJobTypeId = item.Id;
        [self CalculateDueDate];
        break;
    case 2:
        NewBid.BidSalutationId = item.Id;
        break;
    case 5:
        NewBid.BidTextId = item.Id;
        break;


}

//reload the grid no matter what changed
[_tableView reloadData];
}

强制它在主踏板上执行,如:

dispatch_async(dispatch_get_main_queue(), ^{

    //Do what you need to update the UI

});

您确定在主线程上执行了
success
回调吗?提示:您可以使用
[NSThread isMainThread]
进行签出。谢谢您的建议,但我确实在其中加入了这个选项,并且主线程是“是”,所以我不认为是这样。。。。但是谢谢你的建议我可以用异步RestKit调用来实现吗?我应该在哪里将其插入计算例程?因为它已经是异步的了……嗨,布兰登,我所做的是,我使用了dispatch\u async(dispatch\u get\u main\u queue()为了尽可能快地更新我的UI,因为有一种情况,我想根据服务器响应更新我的UI,但UI并没有在收到响应后立即更新,所以我强迫它在主线程上使用这个dispatch_async执行UI更新。您可以做的是:dispatch_async(dispatch_get_main_queue(),^{[self.tableView重新加载rowsatindexpaths:[NSArray arrayWithObject:[NSIndexPath IndeExpathForRow:4分区:0]]withRowAnimation:UITableViewRowAnimationNone];});