如何解决iOS Objective C,如何在从关闭不同的视图控制器重新访问时刷新集合视图的视图?
就像问题所问的那样,我有一个案例,我在加载良好的视图控制器上有 2 个集合视图。但是,当我转到弹出控制器并在那里进行更改以影响那些弹出控制器“下方”的集合视图时,集合视图控制器不会更改。
这是我的视图加载代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.shortcutGroups = [[NSMutableArray alloc]init];
self.shortcutItems = [[NSMutableArray alloc]init];
parent = (RegisterViewController *)self.navigationController.parentViewController;
parent.shortcutViewController = self;
[util makeLeftMenu:self];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.ringupQuantity = DEFAULT_RINGUP_QUANTITY;
self.parentShortcutID = 0;
self.editing = NO;
[self reloadShortcutGroupData];
[self refreshShortCutView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:(BOOL)animated];
[self becomeFirstResponder];
[self setEditing:NO animated:NO];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
[parent setLeftView:self];
[parent enableItemLookup:YES];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[self collectionView:self.shortcutGroupCollectionView didSelectItemAtIndexPath:indexPath];
}
这是我的代码,用于从弹出的视图控制器中刷新集合视图:
- (IBAction)doSave:(id)sender {
NSString *barcode = [self.barcodeTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSRange whiteSpaceRange = [barcode rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]];
if (whiteSpaceRange.location != NSNotFound || barcode.length < MIN_BARCODE_LENGTH) {
NSString
*errmsg = [NSString stringWithFormat:@"Barcode must be entered at least %d digits without space.",MIN_BARCODE_LENGTH];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert"
message:errmsg
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
return;
}
Item *item = [self.item copy];
item.barcode = self.barcodeTextField.text;
item.barcode = barcode;
item.name = self.nameTextField.text;
item.cost = [self.costTextField.text doubleValue];
item.price = [self.priceTextField.text doubleValue];
item.quantity = [self.quantityTextField.text doubleValue];
item.mustEnterPrice = [self.mustEnterPriceSwitch isOn] ? YES : NO;
item.taxID = [self.nontaxableSwitch isOn] ? TAX_ID_NO_TAX : TAX_ID_DEFAULT;
item.categoryID = category ? category.idno : 0;
item.quantityDiscountID = discount ? discount.idno : 0;
if (item.idno == 0) { // New item.
[self createItemWithItem:item];
} else {
[self updateItemWithItem:item];
}
//ItemSelectTableViewController *itemSelector =[[ItemSelectTableViewController alloc] init];
dispatch_async(dispatch_get_main_queue(),^{
[[[ShortcutViewController alloc] init] reloadInputViews];
//NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
ShortcutViewController *shortcutView =[[ShortcutViewController alloc] init];
[shortcutView.shortcutGroupCollectionView
selectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]
animated:YES
scrollPosition:UICollectionViewScrollPositionCenteredVertically];
[shortcutView.shortcutGroupCollectionView reloadData];
[shortcutView.shortcutItemCollectionView reloadData];
[shortcutView viewDidLoad];
[shortcutView viewWillAppear:YES];
[shortcutView viewDidAppear:YES];
});
if ([self isEqual:self.navigationController.viewControllers.firstObject]) {
[self dismissViewControllerAnimated:YES completion:nil];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}
collectionview 不会刷新,但是如果我让 cellForItemAtIndexPath 触发,它会刷新,这意味着关于委托的一些事情......我在这里错过了什么?任何帮助将不胜感激,谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。