2012-08-25 69 views
0

我將非常感謝任何幫助 - 我一直在試圖弄清楚如何在嵌套的UITABLEVIEW中更改tabbarcontroller上的選項卡,就像在RayWenderlich.com的教程中一樣像滾輪http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2脈衝,但我真的陷入了困境。我正在使用故事板和xcode 4.4更改wenderlich教程中的Tabbarcontroller選項卡脈衝uitableview

我是幾個星期的xcode的全新手機,所以我很抱歉如果這是一個新手問題。我已經得到了嵌套的水平桌面正常工作,因爲上面的鏈接圖像,但我想使用圖像切換到新標籤,但不能 - 我認爲這是因爲tableview是嵌套的,所以我找不到正確引用層次結構中的tabbarcontroller。

如果我使用ArticleListViewController.m didselect其中教程包含註釋似乎建議插入導航代碼將生成一個NSLog輸出和更改選項卡確定,但只使用圖像上方的一個小薄條(我偶然發現),但但圖像沒有任何反應。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     // Navigation logic may go here. Create and push another view controller 

    //THIS SELECTS WHEN CLICK THINSTRIP JUST ABOVE BUTTONS 
    NSLog(@"ARTICLELISTVIEWCONTROLLER check didSelect: %u", self.tabBarController.selectedIndex); 

    self.tabBarController.selectedIndex = 2; 
     } 

內Horizo​​ntaTableCell.m下面的代碼,當我點擊的實際圖像,但我想不通的tabbarcontroller參考,讓我改變標籤更適當地產生的NSLog輸出。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    //the following line just generates an Error as follows: Property tabBarController not found on object of type 'HorizontalTableCell *' 

    self.tabBarController.selectedIndex = 2; 

    NSLog(@"HORIZONTALTABLECELL DIDSELECT"); 

    } 

我看了看周圍的方式,但無法弄清楚。發現使用appdelegate的提到,但不知道如何做到這一點。不能發佈故事板圖像作爲新用戶,但有一個帶有4個導航控制器的tabbarcontroller出來 - 第一個是ArticleListViewController菜單,其他每個都是viewcontrollers - 我希望把WebView加載鏈接/本地頁面取決於選擇的菜單和其他用於關於屏幕和其他當前空白的屏幕。

請幫忙!

謝謝!

回答

0

我猜你有tabBarController作爲你的應用程序委託中的屬性?

你可以達到你的應用程序代理: [[UIApplication sharedApplication] delegate]

演員,爲您的應用程序代理類和編譯器不會警告你在標籤欄控制器深遠。像這樣:

((YourAppDelegate *) [[UIApplication sharedApplication] delegate]).tabBarController.selectedIndex = 2; 

至於tableview委託方法,ArticleListViewController聽起來像你想要的地方。這些單元應該只是愚蠢的觀點,最多隻有少量的表示邏輯。如果它沒有被調用,請確保已經將其設置爲表視圖的委託(在界面構建器中,如果您遵循了所鏈接的教程)。

+0

謝謝,我想我已經明白了!經過一段時間的拖網捕魚工作。從字面上花了整整一天,大部分時間試圖解決它! AppDelegate * appdelegate1 =(AppDelegate *)[[UIApplication sharedApplication] delegate]; appdelegate1.TBcontroller.selectedIndex = .... – elricardo

相關問題