我有一个非常基本的通用应用程序。这是一个主要的细节。当我从主服务器转移到细节时,我将文本设置在标签中,并使用NSString设置目标视图控制器的标题。这适用于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;
}
}
答案 0 :(得分:1)
拆分视图控制器具有viewControllers属性,索引1处的控制器将是详细控制器。因此,您可以通过输入此代码来完成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文件导入主控制器的.m文件中,您可能必须将self.splitViewController.viewcontrollers [1]强制转换为您的详细控制器类。
编辑后:
如果细节控制器嵌入在导航控制器中,那么这样的代码应该可以工作,
- (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];
}