gpt4 book ai didi

iphone - BarButtonItem 的标题未更新

转载 作者:搜寻专家 更新时间:2023-10-30 20:22:36 25 4
gpt4 key购买 nike

我在整个项目中使用这段代码来更新我的 UIBarButtonItem 的标题。

在这个特定的类中,我有一个 NSFetchedResultsController,我想获取它的计数以设置为按钮的标题。

我在 ViwDidLoad 中调用这段代码,但它似乎是在获取之前调用的,因此计数始终为 0。我尝试将它放在 Fetch 委托(delegate)方法的末尾,但这也无济于事.有任何想法吗?当我 NSLog 获取委托(delegate)方法中的计数时,它是正确的。

self.myBarButton.title = [NSString stringWithFormat: @"%i count", [fetchedResultsController.fetchedObjects count]];

viewDidLoad

- (void)viewDidLoad
{
[super viewDidLoad];

if (managedObjectContext == nil)
{
self.managedObjectContext = [(TestAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

NSSet *filteredFromSession=[selectedSession.property filteredSetUsingPredicate:[NSPredicate predicateWithFormat: @"name == %@",name]];
if ([filteredFromSession count] > 0)
{
self.exercise = [filteredExercisesFromSession anyObject];
}
self.setLabel.title = [NSString stringWithFormat: @"%i sets", [fetchedResultsController.fetchedObjects count]];
}

最佳答案

很可能在你这样做的时候,

self.setLabel.title = [NSString stringWithFormat: @"%i sets", [fetchedResultsController.fetchedObjects count]];

fetchedResultsControllernil

如果您为 fetchedResultsController 定义了一个 getter 方法并将其声明为属性,我建议您在上面的行之前执行 fetch,

NSError * error;
if (![self.fetchedResultsController performFetch:&error]) {
// Error
}

基本上确保在设置标题之前完成抓取。完成此操作后,您可能想要从您现在正在做的地方删除提取。

关于iphone - BarButtonItem 的标题未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6489542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com