xcode '-[UITableViewController loadView] 加载了“MySubscriptionsViewController”笔尖,但没有得到 UITableView。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16394565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:20:35  来源:igfitidea点击:

'-[UITableViewController loadView] loaded the "MySubscriptionsViewController" nib but didn't get a UITableView.'

iphonexcode

提问by Adnan Khan

I updated my xcodeusing 6.1 simulator, my app was working fine for 5.1 simulator,

我更新了我xcode使用的 6.1 模拟器,我的应用程序在 5.1 模拟器上运行良好,

now i am getting the following error :

现在我收到以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MySubscriptionsViewController" nib but didn't get a UITableView.' 

my header file:

我的头文件:

#import <UIKit/UIKit.h>

@interface MySubscriptionsViewController : UITableViewController{

}

@property (nonatomic,retain) NSString *serverAddress;
@property (nonatomic, retain) UITextField *airportField;
@property (nonatomic, retain) NSMutableArray *airportList;

@property (nonatomic, retain) NSMutableArray *colCode;
@property (nonatomic, retain) NSMutableArray *colAirport;
@property (nonatomic, retain) NSMutableArray *colStartDate;
@property (nonatomic, retain) NSMutableArray *colStartTime;
@property (nonatomic, retain) NSMutableArray *colEndTime;
@property (nonatomic, retain) NSMutableDictionary *tempAirport;


@property (nonatomic,strong) NSDictionary *countryList;
@property (nonatomic,strong) NSArray *countryKeys;

- (IBAction)Meetup:(id)sender;
- (IBAction)ViewBeacon:(id)sender;
-(IBAction)gotoHome:(id)sender;

-( void)beacon:(NSString *)theStr;

@end

my m file:

我的 m 文件:

#import "MySubscriptionsViewController.h"
#import "MybeaconsViewController.h"
#import "SBJsonParser.h"
#import "GridTableViewCell.h"
#import "MeetupViewController.h"
#import "ViewBeaconViewController.h"
#import "DataClass.h"
#import "MemberPanelViewController.h"


@interface MySubscriptionsViewController ()

@end

@implementation MySubscriptionsViewController
@synthesize countryList,countryKeys,serverAddress,airportField,airportList,tempAirport,colStartTime,colEndTime,colStartDate,colAirport,colCode;


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}




- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0,0);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    DataClass *obj=[DataClass getInstance];  



    // serverAddress = @"http://www.cloudnetpk.com/transbeacon_design/services";
    NSString *strURL = [NSString stringWithFormat:@"http://www.cloudnetpk.com/transbeacon_design/services/get_my_beacon_subscriptions.php?code=%@",obj.str];
    NSLog(@" url => %@",strURL);
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
    NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

    SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSArray *datos = [parser objectWithString:strResult error:nil];

    tempAirport = [[NSMutableDictionary alloc] init];
    airportList = [[NSMutableArray alloc] init];
    colStartTime = [[NSMutableArray alloc] init];
    colEndTime = [[NSMutableArray alloc] init];
    colStartDate= [[NSMutableArray alloc] init];
    colAirport= [[NSMutableArray alloc] init];
    colCode= [[NSMutableArray alloc] init];
    countryList = datos;

    NSLog(@"beacons count %d",datos.count);
    for (int i=0; i<datos.count; i++){
        int a=0;

        NSString *startDate = [[[datos objectAtIndex:i] objectForKey:@"start_date" ] lowercaseString];
        NSString *airPort= [[[datos objectAtIndex:i] objectForKey:@"airport" ] lowercaseString];
        NSString *startTime = [[[datos objectAtIndex:i] objectForKey:@"start_time" ] lowercaseString];
        NSString *endTime = [[[datos objectAtIndex:i] objectForKey:@"end_time" ] lowercaseString];
        NSString *code = [[[datos objectAtIndex:i] objectForKey:@"code" ] lowercaseString];

        //NSLog(@" here =>%@",code);
        [colStartDate insertObject:startDate atIndex:i ];
        [colAirport insertObject:airPort atIndex:i ];
        [colStartTime insertObject:startTime atIndex:i ];
        [colEndTime insertObject:endTime atIndex:i ];
        [colCode insertObject:code atIndex:i];


        //[ tempAirport setObject:lcString  forKey:lcStringValue];
    }



    [super viewDidLoad];





}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [countryList count];
}

/*
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    
 UITableViewCell *cell =[[UITableViewCell alloc]
 initWithStyle:UITableViewCellStyleDefault
 reuseIdentifier:@"cell"];
 NSString *currentCountryName=[countryKeys objectAtIndex:[indexPath row]];
 [[cell textLabel] setText:currentCountryName];
 //cell.detailTextLabel.text=@"testing here ";
 return cell;
 }
 */
-(UITableViewCell *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    static NSString *CellIdentifier = @"SectionHeader"; 
    //UITableViewCell *headerView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] ;

    UIImage *myImage=[UIImage imageNamed:@"top_bar.png"];
    UIImageView *imageView =[[UIImageView alloc] initWithImage:myImage];
    imageView.frame= CGRectMake(0, 0, 400, 50);
    [headerView addSubview:imageView];   



    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110,3, tableView.bounds.size.width - 170,40)];  
    label.text = @"Subscriber List";
    label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; 
    label.font = [UIFont fontWithName:@"Arial-BoldMT" size:16]; 
    label.backgroundColor = [UIColor clearColor];
    [headerView addSubview:label];



    UIButton *circularButton = [UIButton buttonWithType:UIButtonTypeCustom];    
    CGRect circularRect = CGRectMake(5.0, 5, 58.0, 32.0);
    [circularButton setFrame:circularRect];
    [circularButton addTarget:self action:@selector(Meetup:) forControlEvents:UIControlEventTouchUpInside]; 
    UIImage *buttonImage = [UIImage imageNamed:@"back_btn.png"];
    [circularButton setImage:buttonImage forState:UIControlStateNormal];
    [headerView addSubview:circularButton];    


    UIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom];    
    CGRect circularRectHome = CGRectMake(250.0, 5, 58.0, 32.0);
    [homeButton setFrame:circularRectHome];
    [homeButton addTarget:self action:@selector(gotoHome:) forControlEvents:UIControlEventTouchUpInside]; 
    UIImage *buttonImageHome = [UIImage imageNamed:@"home_btn.png"];
    [homeButton setImage:buttonImageHome forState:UIControlStateNormal];
    [headerView addSubview:homeButton];   

    return headerView;
}  


-(IBAction)gotoHome:(id)sender{
    // redirect
    MemberPanelViewController *window =[[MemberPanelViewController alloc]init];
    [self presentModalViewController:window animated:YES];

}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 50;
}


- (IBAction)Meetup:(id)sender{
    NSLog(@" button clicked here");
    MeetupViewController *window =[[MeetupViewController alloc]init];
    [self presentModalViewController:window animated:YES];



}

- (IBAction)ViewBeacon:(id)sender{
    ViewBeaconViewController *window=[[ViewBeaconViewController alloc]init];
    [self presentModalViewController:window animated:YES];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *CellIdentifier = @"Cell";

    GridTableViewCell *cell = (GridTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[GridTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.lineColor = [UIColor blackColor];
    }

    // Since we are drawing the lines ourself, we need to know which cell is the top cell in the table so that
    // we can draw the line on the top
    if (indexPath.row == 0)
        cell.topCell = YES;
    else
        cell.topCell = NO;

    // Configure the cell.
    //cell.cell1.text = [NSString stringWithFormat:@"%i",indexPath.row];
    //cell.cell2.text = [NSString stringWithFormat:@"%i", indexPath.row];
    //cell.cell3.text = @"test here text";



    cell.cell1.text =[colStartDate objectAtIndex:indexPath.row];
    cell.cell2.text =[colAirport objectAtIndex:indexPath.row];
    cell.cell3.text =[colStartTime objectAtIndex:indexPath.row];
    cell.cell4.text = [colEndTime objectAtIndex:indexPath.row];

    NSString *value = [colCode objectAtIndex:indexPath.row];
    NSLog(@" value => %@",value);

    UIButton *circularButton = [UIButton buttonWithType:UIButtonTypeCustom];    
    CGRect circularRect = CGRectMake(260.0, 2, 60.0, 40.0);
    [circularButton setFrame:circularRect];
    [circularButton addTarget:self action:@selector(beacon:) forControlEvents:UIControlEventTouchUpInside];

    circularButton.tag=value;
    UIImage *buttonImage = [UIImage imageNamed:@"view.png"];
    [circularButton setImage:buttonImage forState:UIControlStateNormal];
    [cell.contentView addSubview:circularButton];    

    return cell;
}

-( void)beacon:(NSString *)theStr{
    NSInteger *tid = ((UIControl*)theStr).tag;
    NSLog(@" here is parameter %@",tid);


    ViewBeaconViewController *window=[[ViewBeaconViewController alloc]init];
    //   window.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    window.theDataYouWantToPass =tid; 
    window.lastscreen =@"subscription"; 
    [self presentModalViewController:window animated:YES];

}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

回答by Nitin Gohel

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MySubscriptionsViewController" nib but didn't get a UITableView.'This error Ocurce becouse some bellow issue.

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UITableViewController loadView] 加载了“MySubscriptionsViewController”笔尖但没有获得 UITableView。这个错误发生是因为一些波纹管问题。

I think the problem is because you are subclassing UITableViewController instead of UIViewController. you need to put UIViewControlleras a subclass and connect IBoutlet of UITableviewin XIBwith its delegare. your TableVIewin UIViewof XIBso you just connect fileOWner to UIViewas a View and UITableview with your TableView Outlate.

我认为问题是因为您正在继承 UITableViewController 而不是 UIViewController。您需要将其UIViewController作为子类并将其连接UITableviewXIB中的 IBoutlet 及其委托。你TableVIewUIView厦门国际银行,所以你只需连接fileOWner到UIView一个视图和UITableView的与你的TableView Outlate。

@interface MySubscriptionsViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

@interface MySubscriptionsViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

OR

或者

else there you remaining some referance of old copy you trying with restart xcode and remove catch or clean derive data

否则,您仍然可以参考您尝试重新启动 xcode 并删除捕获或清除派生数据的旧副本

回答by cam_271

I just had the same issue; I fixed it by subclassing my newly created viewController file.

我刚刚遇到了同样的问题;我通过继承我新创建的 viewController 文件来修复它。

I was subclassing my newly created tableView file by mistake.

我错误地继承了我新创建的 tableView 文件。

Or

或者

If you want the table view to be the root view in your initial view (it will fill up the whole screen with cells) then you will delete the view in the project outline. second you will control drag the table view in the project outline to the menu (above it) and then you will click delegate for the outlet and do the same for the data source. finally you will open the table view controller file and add UITableViewDelegate and UITableViewDataSource so that it looks like this (using your created name of course).

如果您希望表格视图成为初始视图中的根视图(它将用单元格填满整个屏幕),那么您将删除项目大纲中的视图。其次,您将控制将项目大纲中的表格视图拖动到菜单(上方),然后您将单击插座的委托并对数据源执行相同操作。最后,您将打开表视图控制器文件并添加 UITableViewDelegate 和 UITableViewDataSource 使其看起来像这样(当然使用您创建的名称)。

class MainMenuTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource

类 MainMenuTableViewController:UITableViewController、UITableViewDelegate、UITableViewDataSource

Hope this helps.

希望这可以帮助。