1
所以我需要你的幫助! 我創建了一個UITableViewController
:ContactDetailViewController
。 在筆尖文件中的IB中,我在表格視圖前添加了一個視圖,並將它連接到headerView
- 在.h文件中聲明的UIView
。 我還創建了一個觀點:CustomerHeaderView
然而,當我運行下面的代碼,它在下面的行拋出一個異常:UITableViewController和viewForHeaderInSection問題
headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];
被拋出的錯誤是:
2010-05-20 10:59:50.405 X[19620:20b] *** -[UIView initWithNibName:bundle:]: unrecognized selector sent to instance 0x3ca4fa0
2010-05-20 10:59:50.406 X[19620:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView initWithNibName:bundle:]: unrecognized selector sent to instance 0x3ca4fa0
'
所以任何想法的人?
非常感謝, 菲奧娜
//
// ContactDetailViewController.m
// X
//
// Created by Fiona on 19/05/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ContactDetailViewController.h"
#import "DisplayInfoViewController.h"
#import "ActionViewController.h"
#define SectionHeaderHeigth 200
@implementation ContactDetailViewController
@synthesize name;
@synthesize date;
@synthesize headerView;
@synthesize nextAction;
@synthesize nameLabel;
@synthesize usernameLabel;
@synthesize nextActionTextField;
@synthesize dateLabel;
@synthesize notesTableView;
@synthesize contactInfoButton;
@synthesize backgroundInfoButton;
@synthesize actionDoneButton;
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int numOfRows;
NSLog(@"section: %d", section);
switch (section){
case 0:
numOfRows = 0;
break;
case 1:
numOfRows = 3;
break;
default:
break;
}
return numOfRows;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0){
headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];
// headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];
return headerView;
}else{
return nil;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return SectionHeaderHeigth;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
-(IBAction)displayContactInfo:(id)sender{
DisplayInfoViewController *divc = [[DisplayInfoViewController alloc] init];
divc.textView = self.nextAction;
divc.title = @"Contact Info";
[self.navigationController pushViewController:divc animated:YES];
[divc release];
}
-(IBAction)displayBackgroundInfo:(id)sender{
DisplayInfoViewController *divc = [[DisplayInfoViewController alloc] init];
divc.textView = self.nextAction;
divc.title = @"Background Info";
[self.navigationController pushViewController:divc animated:YES];
[divc release];
}
-(IBAction)actionDone:(id)sender{
ActionViewController *avc = [[ActionViewController alloc] init];
avc.title = @"Action";
avc.nextAction = self.nextAction;
[self.navigationController pushViewController:avc animated:YES];
[avc release];
}
- (void)dealloc {
[name release];
[date release];
[nextAction release];
[nameLabel release];
[usernameLabel release];
[nextActionTextField release];
[dateLabel release];
[notesTableView release];
[contactInfoButton release];
[backgroundInfoButton release];
[actionDoneButton release];
[headerView release];
[super dealloc];
}
@end
嗨Andiih,感謝您花時間看它..我實際上有一個UIViewController在一個點上,但改變了它。 所以我回到了UIViewController。 headerView = [[UIViewController alloc] initWithNibName:@「ContactHeaderDetail」bundle:nil]; 我也更新了headerView的聲明:UIViewController * headerView。 現在收到以下錯誤時拋出拋出: 終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因:「*** - [UIViewController中SETFRAME:]: 上什麼可能導致此任何想法? 謝謝 菲奧娜 – Fiona 2010-05-20 10:17:11
是的。它非常明顯。該框架是視圖的一部分(而不是視圖控制器),因此您需要使用[thing.view setFrame:]而不是[thing setFrame](或點符號等值)。對我來說很明顯,你需要回到文檔並理解視圖和視圖控制器是什麼。我強烈建議在iTunesU上使用CS193P講座系列。它的斯坦福大學課程。花1天的時間現在確定基礎知識將節省時間從長遠來看! – Andiih 2010-05-20 12:07:07