0
這是靜態的導航欄我在我的項目是如何設置的,但要在動態的方式做的,這裏是兩個類型的代碼...創建導航欄dynamatically在IOS
viewsArray = [[NSArray alloc] init];
AfterloginViewController *toolsnavigation = [[AfterloginViewController alloc] init];
toolsnavigation.tabBarItem.image = [UIImage imageNamed:@"cool.png"];
[toolsnavigation setTitle:@"Tools"];
UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:toolsnavigation];
MapViewController *myridenavigation = [[MapViewController alloc] init];
myridenavigation.tabBarItem.image = [UIImage imageNamed:@"cool.png"];
[myridenavigation setTitle:@"Login"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myridenavigation];
viewsArray = [NSArray arrayWithObjects:nav0,nav1,nav2,nav3,nav4,nav5,nav6,nav7,nav8, nil];
tabbarController = [[UITabBarController alloc] init];
[tabbarController setViewControllers:viewsArray];
self.window.rootViewController = tabbarController;
現在我得到來自網址的數據並希望將其分配爲動態導航項目。但我現在已經開始拼命了,不知道該怎麼做。
NSString *loginstring = [NSString stringWithFormat:@"%@nvgationarray.php",mydomainurl];
NSMutableData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: loginstring]];
NSDictionary *allData = [NSJSONSerialization JSONObjectWithData:dataURL options:0 error:nil];
int i = 0;
for(NSDictionary *stat in allData)
{
NSString *ssprst = [stat objectForKey:@"tab_type"];
NSString *ssprst1 = [stat objectForKey:@"tab_name"];
NSString *ssprst2 = [stat objectForKey:@"tab_id"];
NSString *ssprst3 = [stat objectForKey:@"icon"];
NSLog(@"all data ===== :::: %@ %@ %@ %@",ssprst,ssprst1,ssprst2,ssprst3);
NSLog(@"++++++++++++++++++++++++++++++++++++++++++++++");
AbcViewController *myridenavigation = [[AbcViewController alloc] init];
myridenavigation.tabBarItem.image = [UIImage imageNamed:@"cool.png"];
[myridenavigation setTitle:@"Login"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myridenavigation];
i++;
}
你要分配數據同步(等待數據接收,然後創建導航欄)?或異步(無需等待數據接收,做什麼,當數據接收創建導航欄) –
數據正在接收,現在我必須分配到導航控制器.. – Shyantanu
所以它是同步?你想創建大量的uiviewcontroller或uinavigationcontroller嗎?我創建許多uinavigationcontroller似乎很奇怪。你想保留uinavigationcontroller的記憶嗎? –