2012-01-05 21 views
1

嗨,我正在开发的应用程序,其中有将在单一窗口多个表,代码都精细构建得到了成功,但是当我在刺激运行代码它显示的错误为:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a71730'多TABEL查看在单一窗口

请找到我的代码并提供siome建议来解决它。

代码遵循

#import <UIKit/UIKit.h> 

@class ViewController; 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) ViewController *viewController; 

@end 

@implementation AppDelegate 

@synthesize window = _window; 
@synthesize viewController = _viewController; 

- (void)dealloc 
{ 
    [_window release]; 
    [_viewController release]; 
    [super dealloc]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
@end 

的ViewController:

#import <UIKit/UIKit.h> 
#import "tabelOne.h" 
#import "tabelTwo.h" 
#import "tabelThree.h" 

@interface ViewController : UIViewController{ 
    tabelOne *tabel1; 
    tabelTwo *tabel2; 
    tabelThree *tabel3; 


    UITableView *myTableView; 
    UITableView *myTableView1; 
    UITableView *myTableView2; 

} 

@property (retain, nonatomic) IBOutlet UITableView *myTableView; 
@property (retain, nonatomic) IBOutlet UITableView *myTableView1; 
@property (retain, nonatomic) IBOutlet UITableView *myTableView2; 

@end 


#import "ViewController.h" 

@implementation ViewController 
@synthesize myTableView; 
@synthesize myTableView1; 
@synthesize myTableView2; 




- (void)viewDidLoad { 
    [super viewDidLoad]; 
    if (tabel1 == nil) { 
     tabel1 = [[tabelOne alloc] init]; 
    } 
    if (tabel2 == nil) { 
     tabel2 = [[tabelTwo alloc] init]; 
    } 
    if (tabel3 == nil) { 
     tabel3 = [[tabelThree alloc] init]; 
    } 

    [myTableView setDataSource:tabel1]; 
    [myTableView1 setDataSource:tabel2]; 
    [myTableView2 setDataSource:tabel3]; 

    [myTableView setDelegate:tabel1]; 
    [myTableView1 setDelegate:tabel2]; 
    [myTableView2 setDelegate:tabel3]; 


} 


- (void)viewDidUnload 
{ 
    [self setMyTableView:nil]; 
    [self setMyTableView1:nil]; 
    [self setMyTableView2:nil]; 

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

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

- (void)dealloc { 
    [myTableView release]; 
    [myTableView1 release]; 
    [myTableView2 release]; 
    [super dealloc]; 
} 
@end 

表之一:

#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 

@interface tabelOne : UITableViewCell <UITableViewDataSource, UITableViewDelegate>{ 
    NSMutableArray *items; 
} 

@end 
#import "tabelOne.h" 

@implementation tabelOne 


-(void)loadView 
{ 
    if (items == nil) { 
     items = [[NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"6",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",nil] retain]; 
    } 
} 

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 
{ 
    return [items count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyIdentifier"]; 
    } 
    cell.textLabel.text = [NSString stringWithFormat:@"1.%@" ,[items objectAtIndex:indexPath.row]]; 
    return cell; 
} 

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    return UITableViewCellEditingStyleDelete; 

} 
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if(editingStyle == UITableViewCellEditingStyleDelete) {  
     //Delete the object from the table. 
     [items removeObjectAtIndex:indexPath.row]; 
     [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

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

@end 

和类似的代码表2和3

回答

0

网络连接rst:
您的表的子类是UITableViewCell,应该是UITableView

第二个:
我假设视图控制器是tableviews的代表。 您是否已将tableviews delegates和datasources链接到NIB中的视图控制器?

视图控制器必须为表提供数据。 这就是例外说的: - 无法识别的选择器。 (tableView:numberOfRowsInSection:

此方法是UITableViewDatasource的一部分。您必须实现不同的数据源方法。 你可以看到它通过使控制器方法符合协议为这样:

@inteface ViewController : UIViewController <UITableViewDelegate, UITableViewDatasource> 
.... 
@end 

你应该看看的UITableView参考here

0

首先,请检查是否的loadView在tableOne类执行。 并注意tableOne是UITableViewCell的子类,它应该是UITableView正确..?

+0

嗨Vishy,如何检查loadView在tableOne类中执行? – user1118664 2012-01-09 04:30:00

+0

嗨,你可以把一个NSLog和检查,或者你可以使用断点.. – vishy 2012-01-09 08:38:44