简体   繁体   English

使用UITableView时,ios-tableView:numberOfRowsInSection…NSInvalidArgumentException

[英]ios - tableView:numberOfRowsInSection …NSInvalidArgumentException when working with UITableView

I have this header: 我有这个标题:

@interface MyBusinessesController : UIViewController

@property (weak, nonatomic) IBOutlet UITableView *businessList;

@property (weak, nonatomic) IBOutlet UILabel *loadingLabel;

@end 

and I have this in my .m file: 我的.m文件中有这个:

#import "MyBusinessesController.h"

@interface MyBusinessesController ()

@end

@implementation MyBusinessesController

@synthesize businessList;
@synthesize loadingLabel;

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

       NSLog(@"HIDING 1");
    // HIDE THE LIST UNTIL IT LOADS
    self.businessList.hidden=TRUE;
       NSLog(@"HIDING 2");    
}

- (void)viewDidUnload
{
    [self setLoadingLabel:nil];
    [self setBusinessList:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

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

@end

When this controller runs, both of the NSLOG lines execute, and the exception happens after that. 当该控制器运行时,两条NSLOG行都将执行,并且此后会发生异常。

Here is the exception: 这是例外:

-[MyBusinessesController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a8f330
2012-07-29 21:31:38.355 BusinessPlan[3973:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyBusinessesController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6a8f330'
*** First throw call stack:
(0x13d5022 0x1566cd6 0x13d6cbd 0x133bed0 0x133bcb2 0x1fd06b 0x1ff862 0xad66d 0xad167 0xb0134 0xb4623 0x5dd42 0x13d6e42 0x1d8d679 0x1d97579 0x1d1c4f7 0x1d1e3f6 0x1d1dad0 0x13a999e 0x1340640 0x130c4c6 0x130bd84 0x130bc9b 0x12be7d8 0x12be88a 0x1f626 0x1bfd 0x1b65)

Would anyone be able to help me understand what is going wrong here? 谁能帮助我了解这里出了什么问题?

Thanks! 谢谢!

You've probably set up the MyBussinessViewController as the datasource in interface builder but you didn't set up the datasource methods in it. 您可能已经在接口构建器中将MyBussinessViewController设置为数据源,但未在其中设置数据源方法。 You can check by right clicking on the tableview in interface builder and seeing what the datasource field is connected to. 您可以通过右键单击界面构建器中的表视图并查看数据源字段所连接的内容来进行检查。

For reference you need: 供参考,您需要:

tableView:numberOfRowsInSection:
numberOfSectionsInTableView:
tableView:cellForRowAtIndexPath:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

Happy coding. 快乐的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM