gpt4 book ai didi

ios - 在 Split View中执行 "prepare for segue"方法

转载 作者:行者123 更新时间:2023-11-29 03:08:33 24 4
gpt4 key购买 nike

我有一个非常基础的通用应用程序。这是一个主要的细节。当我从主视图转到细节 View 时,我将文本设置在标签中,并使用 NSString 设置目标 View Controller 的标题。这在 iPhone 上工作正常,但在 iPad 上,它没有设置标题或标签。这是我用来设置所有内容的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *object = dailyGramsNumbers[indexPath.row];
NSString *object1 = dailyGramsBody [indexPath.row];
[[segue destinationViewController] setDetailItem:object1];
[[segue destinationViewController] setTitle:object];

}
}

感谢您的帮助!

这是我现在使用的代码(除了上面的代码):

- (void)tableView:

(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSString *object = dailyGramsNumbers[indexPath.row];
[self.splitViewController.viewControllers[1] setTitle:object];

self.detailViewController.detailItem = object;
}
}

最佳答案

Split View Controller 有一个 viewControllers 属性,索引 1 处的 Controller 将是细节 Controller 。因此,您可以通过输入此代码在 iPad 版本上完成相同的任务,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *object = dailyGramsNumbers[indexPath.row];
NSString *object1 = dailyGramsBody[indexPath.row];
[self.splitViewController.viewControllers[1] setDetailItem:object1];
[self.splitViewController.viewControllers[1] setTitle:object];
}

您应该将 DetailController.h 文件导入到主 Controller 的 .m 文件中,并且您可能必须将 self.splitViewController.viewcontrollers[1] 转换为您的细节 Controller 类。

编辑后:

如果细节 Controller 嵌入到导航 Controller 中,这样的代码应该可以工作,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *object = dailyGramsNumbers[indexPath.row];
NSString *object1 = dailyGramsBody[indexPath.row];
[(DetailViewController *)[self.splitViewController.viewControllers[1] topViewController] setDetailItem:object1];
[(DetailViewController *)[self.splitViewController.viewControllers[1] topViewController] setTitle:object];
}

关于ios - 在 Split View中执行 "prepare for segue"方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22491764/

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