EAD*_*EAD 1 objective-c uitableview uiviewcontroller ios
我正在忙着制作一个从.plist加载大量名称的应用程序。我已经进行了设置,以使.plist加载到UiTableView中。现在的问题是,每当尝试打开带有名称表的菜单时,都会收到错误代码。
这是错误消息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fc748e37ea0'
这是我的viewController.m
#import "ViewController.h"
#import "Stuff.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Stuff *s = [[Stuff alloc] init];
[s getStuff];
self.items = [[NSMutableArray alloc] initWithArray:s.stuff];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath
{
NSString *id = @"plistdata";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id forIndexPath:indexPath];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:id];
}
cell.textLabel.text = self.items[indexPath.row];
return cell;
}
@end
Run Code Online (Sandbox Code Playgroud)
谢谢!
根据Matt所说的:您得到的错误是UIViewController类(所有视图控制器的基类)无法识别消息tableView:numberOfRowsInSection:
以某种方式在创建视图控制器时,将创建通用的UIViewController对象,而不是自定义ViewController类的实例。
其原因取决于您如何创建视图控制器。
如果使用调用的代码创建它-[UIViewController initWithNibName:bundle:]
,则可能是在创建UIViewController的实例,而不是自定义的ViewController类:
ViewController *myVC = [[UIViewController alloc] initWithNibName: @ViewController"
bundle: nil];
Run Code Online (Sandbox Code Playgroud)
如果使用情节提要创建它,则可能是情节提要配置不正确。
为了帮助您弄清楚为什么要获得通用的UIViewController而不是自定义类,您需要告诉我们如何创建自定义视图控制器的实例。