2016-03-10 62 views
0

我是Objective C的初學者,我想爲我的標籤欄控制器創建一個類,以添加以API命名的項目添加項目,這些項目鏈接到我的TableViewController(這裏是ScheduleListViewController )。帶tabviewcontroller的程序化標籤欄

我已經這樣做了,但它不起作用,因爲我認爲(而且肯定)我做得很糟糕。

所以爲了解釋我的目標,我必須在我的標籤欄中使用它的ScheduleListViewController(這是一個tableViewController)創建一個項目。

這裏是我的代碼:

#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"]]; 
    } 
} 

謝謝你們

+0

你能否把一個斷點後張貼問題at [sett.tabBarItem setTitle:[item objectForKey:@「name」]]; –

+0

@KumarUtsav但沒有崩潰,但未達到斷點 –

回答

0

下面的代碼行for (id item in jsonResult)

應改爲 for (NSDictionary *item in jsonResult)