2012-09-20 29 views
0

我已經做了一個Tabbed Bar應用程序在Xcode和第一個選項卡是Decors。我問了一個關於將XIB項目集成到StoryBoard選項卡式項目中的問題。Xcode錯誤與鏈接視圖控制器與UITableView

我已經在這個整合成功地,和它的作品,但是當我推了Deocrs,或者我收到以下錯誤表格單元格中的一個:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SelectedCellViewController" nib but the view outlet was not set.

如果我把原來的警告我的項目單元格鏈接開始再次工作。

下面是圖片,鏈接和代碼到我的項目,所以你可以看到它是如何工作

StoryBoard Project

XIB Project

enter image description here

enter image description here

DecorsViewController_iPhone.h

#import <UIKit/UIKit.h> 

@interface DecorsViewController_iPhone : UIViewController 

{ 
IBOutlet UITableView *tableViewDecors; 
NSArray *sitesArray; 
NSArray *imagesArray; 
} 


@property (nonatomic, retain) UITableView *tableViewDecors; 
@property (nonatomic, retain) NSArray *sitesArray; 
@property (nonatomic, retain) NSArray *imagesArray; 


@end 

DecorsViewController_iPhone.m

#import "DecorsViewController_iPhone.h" 
#import "SelectedCellViewController.h" 

@interface DecorsViewController_iPhone() 

@end 

@implementation DecorsViewController_iPhone 

@synthesize tableViewDecors; 
@synthesize sitesArray; 
@synthesize imagesArray; 

#pragma mark - View lifecycle 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
    - (void)viewDidLoad { 

// Load up the sitesArray with a dummy array : sites 
NSArray *sites = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", nil]; 
self.sitesArray = sites; 
//[sites release]; 

UIImage *active = [UIImage imageNamed:@"a.png"]; 
UIImage *ae = [UIImage imageNamed:@"b.png"]; 
UIImage *audio = [UIImage imageNamed:@"c.png"]; 
UIImage *mobile = [UIImage imageNamed:@"d.png"]; 
UIImage *net = [UIImage imageNamed:@"e.png"]; 
UIImage *photo = [UIImage imageNamed:@"f.png"]; 
UIImage *psd = [UIImage imageNamed:@"g.png"]; 
UIImage *vector = [UIImage imageNamed:@"h.png"]; 

NSArray *images = [[NSArray alloc] initWithObjects: active, ae, audio, mobile, net, photo, psd, vector, nil]; 
self.imagesArray = images; 
//[images release]; 

[super viewDidLoad]; 
} 


#pragma mark - Table View datasource methods 

// Required Methods 

// Return the number of rows in a section 
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { 
return [sitesArray count]; 
} 

// Returns cell to render for each row 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"CellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
} 

// Configure cell 

NSUInteger row = [indexPath row]; 

// Sets the text for the cell 
//cell.textLabel.text = [sitesArray objectAtIndex:row]; 

// Sets the imageview for the cell 
cell.imageView.image = [imagesArray objectAtIndex:row]; 

// Sets the accessory for the cell 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

// Sets the detailtext for the cell (subtitle) 
//cell.detailTextLabel.text = [NSString stringWithFormat:@"This is row: %i", row + 1]; 

return cell; 
} 

// Optional 

// Returns the number of section in a table view 
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { 
return 1; 
} 

#pragma mark - 
#pragma mark Table View delegate methods 

// Return the height for each cell 
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 78; 
} 

// Sets the title for header in the tableview 
-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  { 
return @"Decors"; 
} 

// Sets the title for footer 
-(NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section  { 
return @"Decors"; 
} 

// Sets the indentation for rows 
-(NSInteger) tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 0; 
} 


// Method that gets called from the "Done" button (From the @selector in the line - [viewControllerToShow.navigationItem setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)] autorelease]];) 
- (void)dismissView { 
[self dismissViewControllerAnimated:YES completion:NULL]; 
} 

// This method is run when the user taps the row in the tableview 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

SelectedCellViewController *viewControllerToShow = [[SelectedCellViewController alloc] initWithNibName:@"SelectedCellViewController" bundle:[NSBundle mainBundle]]; 
[viewControllerToShow setLabelText:[NSString stringWithFormat:@"You selected cell: %d - %@", indexPath.row, [sitesArray objectAtIndex:indexPath.row]]]; 
[viewControllerToShow setImage:(UIImage *)[imagesArray objectAtIndex:indexPath.row]]; 

[viewControllerToShow setModalPresentationStyle:UIModalPresentationFormSheet]; 
[viewControllerToShow setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
[viewControllerToShow.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)]]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewControllerToShow]; 
viewControllerToShow = nil; 

    [self presentViewController:navController animated:YES completion:NULL]; 
navController = nil; 

    // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tapped row!" 
//           message:[NSString stringWithFormat:@"You tapped: %@", [sitesArray objectAtIndex:indexPath.row]] 
//           delegate:nil 
//           cancelButtonTitle:@"Yes, I did!" 
//           otherButtonTitles:nil]; 
// [alert show]; 
// [alert release]; 

} 

#pragma mark - Memory management 

- (void)didReceiveMemoryWarning { 
NSLog(@"Memory Warning!"); 
[super didReceiveMemoryWarning]; 
} 

- (void)viewDidUnload { 
self.sitesArray = nil; 
self.imagesArray = nil; 
[super viewDidUnload]; 
} 


//- (void)dealloc { 
//[sitesArray release]; 
//[imagesArray release]; 
// [super dealloc]; 
//} 

@end 

SelectedCellViewController.h

@interface SelectedCellViewController : UIViewController { 
NSString *labelText; 
UIImage *image; 

IBOutlet UILabel *label; 
IBOutlet UIImageView *imageView; 
} 

@property (nonatomic, copy) NSString *labelText; 
@property (nonatomic, retain) UIImage *image; 

@end 

viewControllerToShow.m

#import "SelectedCellViewController.h" 

@implementation SelectedCellViewController 

@synthesize labelText; 
@synthesize image; 

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

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad { 
[super viewDidLoad]; 
[label setText:self.labelText]; 
[imageView setImage:self.image]; 
} 

- (void)viewDidUnload { 
self.labelText = nil; 
self.image = nil; 
//[label release]; 
// [imageView release]; 
[super viewDidUnload]; 
} 

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

@end 
+0

我想通了。我實際上可以使用外部XIB文件,而不是將其與故事板文件一起使用。很酷。我快速學習:)感謝所有幫助過的人。 –

回答

0

檢查「控制器在點擊時顯示的控制器」.XIB在身份檢查器中繼承的類。看起來你沒有設置類爲「將被顯示」的XIB和相同的視圖插座廈門國際銀行。