2014-03-18 21 views
0

我有一個非常基本的通用應用程序。這是一個主要的細節。當我從主人繼續細節時,我將文本設置在標籤中,並使用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

您使用的是SplitViewController?在那種情況下,我想,在iPad上不會執行Segue,因爲兩個部分(主要和細節)都顯示在一起。我只是猜測,但也許這有助於 – Stefan

+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文件,你可能要投自己.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]; 
} 
+0

這是我在RPMasterViewController.m中的代碼(除了我最初發布的代碼之外.-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath if {[[UIDevice currentDevice ] userInterfaceIdiom] == UIUserInterfaceIdiomPad){ 的NSString *對象= dailyGramsNumbers [indexPath.row]; [self.splitViewController.viewControllers [1]的setTitle:對象]; self.detailViewController.detailItem =對象; } } 標籤現在正在工作並且正在設置,但標題不是。 –

+0

@ user2991787,是您在導航控制器中的詳細控制器嗎? – rdelmar

+0

是的,它位於導航控制器中 –