gpt4 book ai didi

ios - 关闭 TableViewController 展开到第一个 Storyboard

转载 作者:行者123 更新时间:2023-11-28 21:24:51 26 4
gpt4 key购买 nike

我在 UINavigationController 中嵌入了一个 UITableViewController。

当我在详细 View (详细 View 在 UITabViewController 中)中单击一个按钮到 showList 时,会显示名为 List 的 UITableViewController(列表 TableView )。如果我点击导航 Controller 中的 Back 按钮,我将回到正确的屏幕:蓝线显示的详细 View

如果我选择一个列表项,委托(delegate)方法 didSelectFromList 会从 didSelectRowAtIndexPath 调用,应用会返回到主屏幕(主视图),如下所示红线。

我要的是紫色线

enter image description here

有什么帮助吗?

尝试 1:

我让代理关闭 List TableVC。

#import "ListTableViewController.h"
@interface CallDetailViewController () <ListTableViewControllerDelegate>
@property (nonatomic, strong) LotListTableViewController * lltvc;
@end


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([[segue identifier] isEqualToString:@"segue_list"]) {
self.lltvc = (ListTableViewController*)segue.destinationViewController;
self.lltvc.delegate = self;
}

}

- (void) showList {
[self performSegueWithIdentifier:@"segue_list" sender:self];
}

#pragma mark LIST SELECTION DELEGATE METHOD

- (void) didSelectFromList:(NSString *)item {
[self.lltvc dismissViewControllerAnimated:YES completion:^{
NSLog(@"Did Select item: %@", item);
}];
}

在列表 TableView Controller 中

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

///.. stuff to find the correct string

[self.delegate didSelectFromList:item];


}

尝试 2:

这里我让 List TableVC 自行消失。

#import "ListTableViewController.h"
@interface CallDetailViewController () <ListTableViewControllerDelegate>

@end


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([[segue identifier] isEqualToString:@"segue_lots"]) {
NSLog(@"GOING TO THE LOT LIST");

UINavigationController * nvc = (UINavigationController*)segue.destinationViewController;
LotListTableViewController *lltvc = [nvc childViewControllers][0];
lltvc.delegate = self;

}

}

- (void) showLotList {
[self performSegueWithIdentifier:@"segue_lots" sender:self];

}
#pragma mark LIST SELECTION DELEGATE METHOD

- (void) didSelectFromList:(NSString *)item {
NSLog(@"Did Select item: %@", item);

}

在列表 TableView Controller 中

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

///.. stuff to find the correct string

[self dismissViewControllerAnimated:YES completion:^{
[self.delegate didSelectFromList:item];

}];
}

我也尝试过从 List TableVC 中的 didSelectRowAtIndexPath

[self.navigationController dismissViewControllerAnimated:YES completion:^{
[self.delegate didSelectFromList:item];

}];

最佳答案

如果你继续推送 View Controller ,它们会被添加到导航堆栈,所以如果你这样做 [self dismiss 或 [self.navigationController dismiss,所有导航堆栈都被清除,你将被带到 rootViewController。

你可以弹出一个 View Controller 或者不是从 detailVC 推送导航 Controller ,而是呈现具有列表 VC 的导航 Controller 。在这种情况下,[self.nav dismissviewCOntroller 将起作用,

关于ios - 关闭 TableViewController 展开到第一个 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38507445/

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