gpt4 book ai didi

ios - 在 Popover tableview 中选择单元格后 UILabel 不刷新

转载 作者:行者123 更新时间:2023-11-29 00:06:51 25 4
gpt4 key购买 nike

好的,所以在 IB 中,我为 iPhone 版本创建了一个带有 TableView 的 ViewController,效果很好。

在 iPad 版本上,如果只是文本,则不能让 tableview 占据整个屏幕。因此,在 iPad Storyboard 中,我在主视图 Controller 上创建了一个按钮,该按钮连接到带有 tableview 的自定义 ViewController,并且它以弹出窗口的形式打开。

打开效果很好,数据正在从带有 TableView 的 ViewController 传递到主视图。在控制台中,我看到标签正在更新,但在屏幕上标签没有更新。

在我用来检索数据的方法中尝试了 [self.view layoutIfNeeded],按照某些人在其他答案中的建议更改了 alpha。我注意到 viewWillAppear 根本没有被调用。尝试将 didSelectRowAtIndex 中的 main vc viewWillAppear 设置为 yes...

当然,当我转到另一个屏幕并返回时,标签会更新。

下面是我如何在弹出窗口中选择一个单元格时使用 tableview 关闭 View Controller 。

[self dismissViewControllerAnimated:YES completion:^{
[vc viewWillAppear:YES];
[vc.view layoutIfNeeded];
[vc updateText:[arrUsers objectAtIndex:indexPath.row]];
}];

是不是我正在解除它阻止主视图 Controller 更新的事实?

这是弹出窗口中的方法:

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];


UIStoryboard * storyboard = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ?
[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] :
[UIStoryboard storyboardWithName:@"Main" bundle:nil];

ViewController *vc = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ?
(ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewControlleriPad"] :
(ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(searching){
if ([copyListOfItems count]>0) {

NSLog(@"Search Results Selected %@", [copyListOfItems objectAtIndex:indexPath.row]);

[vc.lbl_specialties setText:[copyListOfItems objectAtIndex:indexPath.row]];
}
}
else {

self.appDelegate.selectedSpecialty = [arrUsers objectAtIndex:indexPath.row];

NSLog(@"Selected %@", self.appDelegate.selectedSpecialty);


}
[self dismissViewControllerAnimated:YES completion:^{
[vc viewWillAppear:YES];
[vc.view layoutIfNeeded];
[vc updateSpecialtyText:[arrUsers objectAtIndex:indexPath.row]];

}];
}
}

这是上面调用的 View Controller 中的方法。

-(void)updateSpecialtyText:(NSString*)text
{
[super viewWillAppear:YES];

NSLog(@"text to update %@", text);
[self.lbl_specialties layoutIfNeeded];
[self.view layoutIfNeeded];
[self.lbl_specialties setText:text];

NSLog(@"text updated %@", self.lbl_specialties.text);

}

最佳答案

在我看来,而不是

[self dismissViewControllerAnimated:YES completion:^{
[vc viewWillAppear:YES];
[vc.view layoutIfNeeded];
[vc updateText:[arrUsers objectAtIndex:indexPath.row]];
}];

你应该尝试

[(ViewController *)self.presentingViewController updateText:[arrUsers objectAtIndex:indexPath.row]];
[self dismissViewControllerAnimated:YES completion:nil];

如果 ViewController 嵌入到 UINavigationController 中,请改用下面的代码。

[(ViewController *)[(UINavigationController *)self.presentingViewController topViewController] updateText:[arrUsers objectAtIndex:indexPath.row]];
[self dismissViewControllerAnimated:YES completion:nil];

关于ios - 在 Popover tableview 中选择单元格后 UILabel 不刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47763193/

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