2013-01-09 55 views
0

有人能告訴我如何使用故事板將界面分配給表格視圖元素嗎?我正在製作一款醫療計算器,它針對每個方程都有不同的計算器,而且我需要幫助製作代碼,以指示元素推向另一個界面。這是因爲對於每一個等式來說,都有不同的領域需要填寫(例如年齡,氧氣水平,是否有人患有糖尿病,身高等等)。並不是每個方程都需要相同的領域。爲每個表格視圖項目分配一個單獨的用戶界面

我也試着這樣做:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Deselect row 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    // Declare the view controller 
    UIViewController *anotherVC = nil; 

    // Determine the row/section on the tapped cell 
    switch (indexPath.section) { 
     case 0: 
      switch (indexPath.row) { 
       case 0: { 
        // initialize and allocate a specific view controller for section 0 row 0 
        anotherVC = [[BmiViewController alloc] init]; 
        break; 
       } 
       case 1: { 
        // initialize and allocate a specific view controller for section 0 row 1 
        /anotherVC = [[AaOxygenGradientViewController alloc] init]; 
        break; 
       } 
      } 
      break; 
    } 
} 

但這樣做之後,它指回到了最初的故事板文件(因爲我已經創建programmicatally接口裏面是空的),而不是顯示我的測試警報彈出。

此外,是否有可能製作一堆表格視圖單元格,然後讓每個視圖控制器在故事板中的每個其他視圖控制器中繼續?

非常感謝!

回答

0

首先,您正在運行deselectCellAtIndexPath?這是什麼原因?如果您只是試圖刪除藍色突出顯示,那麼最好更改單元的UITableViewCellSelectionStyle(或類似的東西)。

我不確定你要求的第一部分,但對於部分部分,然後是的。

Storyboard設置從tableViewController到其他VC,你想繼續,並給他們所有明智的標識符。

即medicalCalulatorSegue graphSegue userDetailsS​​egue 等等

然後在您的didSelect方法,你將有類似...

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

    switch(indexPath.row) { 
     case 0: 
      [self performSegueWithIdentifier:@"medicalCalulatorSegue"]; 
      break; 
     case 1: 
      [self performSegueWithIdentifier:@"graphSegue"]; 
      break; 
     case 2: 
      [self performSegueWithIdentifier:@"userDetailsSegue"]; 
      break; 
    } 
} 

這一操作將Segue公司給每個不同的視圖控制器取決於選擇哪個單元格。

的理由不deselcting細胞是在你的方法prepareForSegue,則仍可訪問選定單元格的indexPath ...

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
+0

非常感謝你的回覆!我從來不知道執行SegueWithIdentifier,我從來不知道我可以使用它。我仍然是一個xcode的新手。對於我的第一個問題,我曾經問過如何設計和繼續爲每個單獨的表格單元格項目分隔故事板視圖控制器,但我認爲你已經回答了。目前我無法測試新代碼,但謝謝。 –

+0

非常感謝!有用! –

+0

完美!樂意效勞。 – Fogmeister

相關問題