带有tabviewcontroller的编程标签栏

时间:2016-03-10 13:50:53

标签: ios objective-c uitableview

我是Objective C的初学者,我想为我的标签栏控制器创建一个类来添加从API命名的项目添加项目,这些项目链接到我的TableViewController (这里是ScheduleListViewController)。

我已经做到了,但它没有用,因为我认为(并且它确定)我做得很糟糕。

因此,为了解释我的目标,我必须在标签栏中创建一个项目ScheduleListViewControllertableViewController}。

这是我的代码:

#import "ChannelListTsbleBarVC.h"
#import "TVSHOW.h"
#import "ScheduleListTableViewController.h"
#import "TLAnimatedSegue.h"

@interface ChannelListTsbleBarVC ()

@end

@implementation ChannelListTsbleBarVC

- (void)viewDidLoad {
  [super viewDidLoad];
  NSString *url = [NSString stringWithFormat: @"https://apis.is/tv"];
  NSData *JSONData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  NSError* error;
  NSDictionary* json = [NSJSONSerialization
                          JSONObjectWithData:JSONData //1
                          options:kNilOptions
                          error:&error];
  NSArray* jsonResult = [json objectForKey:@"channels"];

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

  for (id item in jsonResult) {
    ScheduleListTableViewController *Channel = [[ScheduleListTableViewController alloc] init];
    UINavigationController *sett = [[UINavigationController alloc] initWithRootViewController: Channel];
    [sett.tabBarItem setTitle:[item objectForKey:@"name"]];
    Channel = [storyboard instantiateViewControllerWithIdentifier:[item objectForKey:@"name"]];
  }
}

谢谢你们

1 个答案:

答案 0 :(得分:0)

以下代码行for (id item in jsonResult)

应该改为     for (NSDictionary *item in jsonResult)

相关问题