2011-07-28 39 views
1

我是iOS開發新手,對變量有疑問。我試圖用標籤欄和導航控制器編寫應用程序,標籤欄是rootViewController。我已經建立了我的應用程序來包含一個包含我的表視圖行爲的.plist,一個UITableViewController和一個詳細視圖控制器。當我在我的應用程序委託中定義導航控制器時,我繼續在初始表視圖控制器的實現文件中出現一個錯誤。調用在不同文件頭中定義的變量?

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

//Get the dictionary of the selected data source. 
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row]; 

//Get the children of the present item. 
NSArray *Children = [dictionary objectForKey:@"Children"]; 

if([Children count] == 0) { 

    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; 
    [self.navigationController pushViewController:dvController animated:YES]; 
    [dvController release]; 
} 
else { 

    //Prepare to tableview. 
    IndustryTableViewController *industryTableViewController = [[IndustryTableViewController alloc] initWithNibName:@"IndustryTableViewController" bundle:[NSBundle mainBundle]]; 

    //Increment the Current View 
    industryTableViewController.CurrentLevel += 1; 

    //Set the title; 
    industryTableViewController.CurrentTitle = [dictionary objectForKey:@"Title"]; 

    //Push the new table view on the stack 
    [self.indNavControl pushViewController:industryTableViewController animated:YES]; 

    industryTableViewController.tableDataSource = Children; 

    [industryTableViewController release]; 
} 

}

我得到的錯誤,當我推堆棧上的新表視圖。我正在導入我的應用程序委託的頭文件,但它仍然不起作用,給我錯誤,「變量沒有在TableViewController.h中定義」。有沒有辦法讓我召喚這個變量,還是有更有效的方法來解決這個問題?

在此先感謝,我真的可以使用任何幫助你給我。

回答

0

你可以得到一個指向您的appDelegate,然後讓你的變量,像這樣:

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate]; 

另一種方法是使用依賴注入並注入參考到控制器中,當你創建。所以基本上定義控制器舉行引用伊娃,然後做到這一點:

[myController new]; 
[myController setController:otherController]; 
0

你是指navigationController與self.navigationController

這意味着navigationController是在您的TableViewController類中定義的變量。

您應該在您的類中定義此變量並修改您的tableviewcontroller的init方法以接收該變量。

0

它說的哪個變量沒有定義?你能分享細節嗎?看起來像下面這樣: self.indNavControl

這個indNavControl是在哪裏定義的?請正確定義它,它應該工作正常。