2011-09-15 64 views
3

我用一个简单的表格视图一个小问题,我无法显示它的应用程序崩溃时,我打开看,这里是代码:iOS的 - 无法加载表视图

familySelect .H:

// familySelect.h 
// fptNew 
// 
// Created by Marco on 14/09/11. 
// Copyright 2011 __MyCompanyName__. All rights reserved. 

#import <UIKit/UIKit.h> 


@interface familySelect : UIViewController { 
    NSArray *colorNames; 
    IBOutlet UITableView *tableView; 
} 

@property (nonatomic, retain) NSArray *colorNames; 

@end 

familySelect.m:

// familySelect.m 
// fptNew 
// 
// Created by Marco on 14/09/11. 
// Copyright 2011 __MyCompanyName__. All rights reserved. 

#import "familySelect.h" 


@implementation familySelect 

@synthesize colorNames; 

// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
/* 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization. 
    } 
    return self; 
} 
*/ 


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

    NSLog(@"eseguito"); 
    self.colorNames = [[NSArray alloc] initWithObjects:@"Red", @"Green", @"Blue", @"Indigo", @"Violet", nil]; 

    //UILabel *label = (UILabel *)[self.view viewWithTag:111]; 
    //label.backgroundColor = [UIColor colorWithRed:0.2f green:0.3f blue:0.4f alpha:0.00000f]; 

} 



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Overriden to allow any orientation. 
    return YES; 
} 


- (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 { 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)TableView numberOfRowsInSection:(NSInteger)section { 
    return [self.colorNames count]; 
} 

// 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]; 
    } 

    // Configure the cell. 
    cell.textLabel.text = [self.colorNames objectAtIndex: [indexPath row]]; 

    return cell; 
} 

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

@end 

,这是控制台输出,当它崩溃:

2011-09-15 17:46:02.788 fptNew[2098:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4e29540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00eab5a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00cda313 objc_exception_throw + 44 
    2 CoreFoundation      0x00eab4e1 -[NSException raise] + 17 
    3 Foundation       0x0002f677 _NSSetUsingKeyValueSetter + 135 
    4 Foundation       0x0002f5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285 
    5 UIKit        0x004b330c -[UIRuntimeOutletConnection connect] + 112 
    6 CoreFoundation      0x00e218cf -[NSArray makeObjectsPerformSelector:] + 239 
    7 UIKit        0x004b1d23 -[UINib instantiateWithOwner:options:] + 1041 
    8 UIKit        0x004b3ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 
    9 UIKit        0x00369628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70 
    10 UIKit        0x00367134 -[UIViewController loadView] + 120 
    11 UIKit        0x0036700e -[UIViewController view] + 56 
    12 fptNew        0x00001e2f -[homeScreen buttonPressed:] + 163 
    13 UIKit        0x002b74fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    14 UIKit        0x00347799 -[UIControl sendAction:to:forEvent:] + 67 
    15 UIKit        0x00349c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    16 UIKit        0x00348a1c -[UIControl touchesBegan:withEvent:] + 277 
    17 UIKit        0x002dbd41 -[UIWindow _sendTouchesForEvent:] + 395 
    18 UIKit        0x002bcc37 -[UIApplication sendEvent:] + 447 
    19 UIKit        0x002c1f2e _UIApplicationHandleEvent + 7576 
    20 GraphicsServices     0x0171f992 PurpleEventCallback + 1550 
    21 CoreFoundation      0x00e8c944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    22 CoreFoundation      0x00deccf7 __CFRunLoopDoSource1 + 215 
    23 CoreFoundation      0x00de9f83 __CFRunLoopRun + 979 
    24 CoreFoundation      0x00de9840 CFRunLoopRunSpecific + 208 
    25 CoreFoundation      0x00de9761 CFRunLoopRunInMode + 97 
    26 GraphicsServices     0x0171e1c4 GSEventRunModal + 217 
    27 GraphicsServices     0x0171e289 GSEventRun + 115 
    28 UIKit        0x002c5c93 UIApplicationMain + 1160 
    29 fptNew        0x00001b48 main + 102 
    30 fptNew        0x00001ad9 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

不明白这有什么错我的代码

感谢您的帮助:)

UPDATE:

有在厦门国际银行文件,我不要连接。

的tableView连接

enter image description here

和文件的所有者连接

enter image description here

是正确的方式联系起来?

回答

0

您需要实现UITableView delegates-

@interface familySelect : UIViewController <UITableViewDelegate,UITableViewDataSource> 

而且,由于你已经宣布tableView作为IBOutlet,我猜你做了一个中笔尖。您还必须在笔尖制作tableView的参考插座。只需右键单击tableView并使用正确的元素连接不同的属性。

2

您必须声明表视图的属性。就像这样:

@property(nonatomic,retain) IBOutlet UITableView *tableView;

和您的接口声明应该是这样的:

@interface familySelect : UIViewController<UITableViewDelegate,UITableViewDataSource> 
{ 
     NSArray *colorNames; 
     UITableView *tableView; 
} 

干杯!

+0

感谢您的帮助,我已经做了更改,但错误仍在此处 –