我試圖創建一個循環動態創建循環
for (int i = 0; i < [tabNumbers count]; i++)
{
UIViewController *viewController;
viewController = [[UIViewController alloc] init];
viewController.title = [tabNumbers objectAtIndex:i];
viewController = [tabNumbers objectAtIndex:1];
[viewControllersList addObject:viewController];
[viewController release];
}
變量,但問題是,當我添加查看陣列我得到隨機的名字一堆視圖控制器。
不是
UIViewController *viewController;
我試圖做這樣的事情
UIViewControlller *[NSString stringWithFormat:@"%@Controller",[tabNumbers objectAtIndex:i]]
但這不起作用
其原因是,是,一旦我創建的意見在循環中,我正在尋找創建一個標籤欄與每個視圖作爲選項卡,然後每個選項卡調用其自己的視圖控制器
我現在不能調用視圖控制器,因爲我不知道每次會產生什麼樣的隨機數。
感謝
鮑勃
哇 - 兩個夢幻般的和及時的反應。
不幸的是,我對Xcode很新穎,並且在吸收方面很慢。我想如果我發佈完整的代碼,它可能有助於解釋我正在嘗試做什麼。
這樣的想法是,用戶可以添加,刪除,移動或重命名標籤欄項目,因爲他們認爲合適的。
,我得的一點是,我可以添加標籤欄項目,但我無法獲取標籤欄項目來創建新表。
我知道代碼是正確的,使標籤欄項目 - 我可以添加儘可能多的標籤欄項目,我想要的。 我知道,如果我只繪製一個標籤欄項目,我可以繪製表格
但我不能做的是獲取多個標籤欄項目,每個繪製一個表格。
我認爲最好的辦法是動態命名視圖控制器,這你們已經證明了我是不可能的。
所以在下以爲是試圖從陣列得到它,但考慮到該陣列也將取決於什麼用戶使標籤欄名稱改變,我看不出這是如何工作的。
有什麼建議嗎?
如有可能,包括一些代碼片段 - 我開始理解代碼,當我讀到它,但我不明白,解釋的定義(如對於視圖控制器標籤)
感謝
鮑勃
- (void)showTabBar
{
GuidelinesAppDelegate *AppDelegate = (GuidelinesAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *viewControllersList = [[NSMutableArray alloc] init];
NSMutableDictionary *tabItemsDict = [[NSMutableDictionary alloc] initWithObjects:tabNumbers forKeys:tabNumbers];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"data.plist"];
UIViewController *viewController;
for (int i = 0; i < [tabNumbers count]; i++)
{
viewController = [[UIViewController alloc] init];
viewController.title = [tabNumbers objectAtIndex:i];
[viewControllersList addObject:viewController];
[viewController release];
}
AppDelegate.tabItemsDict = tabItemsDict;
[self.tabBarController setViewControllers:viewControllersList animated:YES];
for (NSString *s in viewControllersList)
{
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
NSMutableDictionary *tabTableStructureDict = [[NSMutableDictionary alloc] initWithContentsOfFile:DataPath];
AppDelegate.tabTableStructureDict = tabTableStructureDict;
UINavigationController *bNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = bNavigationController;
[self.view addSubview:[navigationController view]];
[bNavigationController release];
[rootViewController release];
}
}
所以,我我收到有關不能夠做什麼,我想要的意見後,我幾乎放棄了什麼,我試圖做的,去和重組從一開始的項目。謝謝你的幫助 –