4

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

现在我收到以下错误:

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

我的头文件:

#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

我的 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
4

2 回答 2

12

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

我认为这个问题是因为你继承 UITableViewController 而不是 UIViewController。您需要将UIViewController其作为子类并将XIBUITableview中的 IBoutlet 与其委托连接。您在XIB中,因此您只需将 fileOWner作为 View 和 UITableview 与您的 TableView Outlate 连接。TableVIewUIViewUIView

@interface MySubscriptionsViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

或者

否则,您还剩下一些旧副本的参考,您尝试重新启动 xcode 并删除捕获或清理派生数据

于 2013-05-06T08:12:43.960 回答
0

我只是遇到了同样的问题;我通过子类化我新创建的 viewController 文件来修复它。

我错误地将我新创建的 tableView 文件子类化。

或者

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

类 MainMenuTableViewController:UITableViewController、UITableViewDelegate、UITableViewDataSource

希望这可以帮助。

于 2015-07-26T14:47:01.030 回答