gpt4 book ai didi

ios - 从 'UIViewController' 转换为不相关类型 'TableViewCell' 总是失败

转载 作者:行者123 更新时间:2023-11-30 13:43:37 25 4
gpt4 key购买 nike

我收到此错误“从“UIViewController”转换为不相关类型“TableViewCell”总是失败”

我正在尝试操作 TableViewCell Controller 中的导出。所以我想将一些数据从 UIViewController 转换到 UITableViewCell。

enter image description here

最佳答案

-[UIStoryboardSegue destinationViewController] 返回一个 UIViewController*。假设 TableViewCellUITableViewCell 的子类,则强制转换没有意义。从我看到的信息来看,您需要检查 destinationViewController 是否指向 UITableViewController 的实例,然后对其进行强制转换。

UIViewController *viewController = [segue destinationViewController];
if ([viewController isKindOfClass:[UITableViewControler class]])
{
UITableViewController *tableViewController = (UITableViewController *) viewController;
}

从那里,您可以使用任何 UITableViewController 的方法访问单元格,可能是那些实现 UITableViewDelegateUITableViewDataSource 的方法。如果您需要更多特定于实现的控制,您可以在检查 destinationViewController 是该类的实例后将其转换为 TableVC

关于ios - 从 'UIViewController' 转换为不相关类型 'TableViewCell' 总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35258607/

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