这是我在项目中设置的静态导航栏,但想以动态方式进行,这是两种类型的代码......
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;
现在我从 URL 获取数据并希望将其分配为动态导航项。但我现在很困惑,不知道该怎么做。
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++;
}