gpt4 book ai didi

swift - 从自定义单元格 Nib 推送到 viewController

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

我使用 UITableViewController 作为源,目标是带有 UITableView 的 UIViewController。

我想从 (a) tableViewCell(在 .xib 中 tableview 的自定义单元格中)推送到 (b) viewController。自定义单元格在 .xib 文件中指定。我试过控制拖动来创建 segue,但我做不到。

如何从 customCell 推送到 UIViewController?我试过了

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("你选择了单元格 #\(indexPath.row)!")

    let destination = FestsViewController()
navigationController?.pushViewController(destination, animated: true)}

我得到没有标签的黑色背景。 enter image description here

最佳答案

你不能。 Segues 仅在 Storyboard中可用。您必须手动进行导航-tableView:didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//some checks
//...

UIViewController *destinationVC = //init it with nib or instantiate from storyboard
//pass some parameters if you need
//e.g.
//destinationVC.prop1 = someValue;
[self.navigationController pushViewController:destinationVC animated:YES];
}

关于swift - 从自定义单元格 Nib 推送到 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33841051/

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