gpt4 book ai didi

ios - 如何在不重启模拟器的情况下将项目添加到 TableView

转载 作者:行者123 更新时间:2023-11-28 22:09:54 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个带有两个按钮的 TableView Controller 。一个添加项目,另一个编辑 TableView 。当我添加一个项目时,控制台说它已经添加了一个项目,但是直到我重新启动模拟器才能看到项目被添加到 TableView 中。当我添加一个项目时,我确保像这样重新加载 tableview:

- (IBAction)addNewItem:(id)sender

{
NSManagedObjectContext *context = [self managedObjectContext];
Item *itemData = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:context];
[itemData setValue:userText.text forKey:@"name"];

NSError *error;

if (![context save:&error])
{
NSLog(@"Couldnt find the save %@", error.localizedDescription);
}

else
{
NSLog(@"It saved properly");
}

[self.tableView reloadData];

}

我只是不明白问题可能是什么......

感谢所有帮助,

提前致谢

最佳答案

添加新项后,tableView 继续显示旧的获取结果。添加item后需要重新获取数据,然后调用[self.tableView reloadData]方法。

关于ios - 如何在不重启模拟器的情况下将项目添加到 TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23173424/

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