我一直在尝试在 Xcode 中实现一个简单的 TableView 。但是我遇到了这个错误:
[UIView tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 0x7fd23bc76bc0
我在网上搜索了一个答案,基本上我能找到的只是我试图向该方法发送一些不存在的东西。如果有人可以解释这里到底发生了什么,为什么会这样,我将如何解决它,我将不胜感激。这是代码:
在 ViewController.h 中:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
@end
在 ViewController.m 中:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
{
NSArray *recipes;
}
- (void)viewDidLoad {
[super viewDidLoad];
recipes = [NSArray arrayWithObjects:@"Eggs", @"Bacon", @"Ham", @"Steak", @"Bread", @"Lettuce", @"Tomatoes", @"Carrots", @"Milk", @"Pizza", @"Chicken", @"Soup", @"Cheese", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [recipes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableID = @"SimpleTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableID];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
如果您需要更多信息,我很乐意为您提供。谢谢。
最佳答案
看起来您已将 TableView 的委托(delegate)属性拖到 UIView 而不是 UiViewController 上。
在 Storyboard中,确保将委托(delegate)属性拖到 Controller ( View 顶部的黄色圆圈)。
关于ios - 尝试实现 TableView 并获取线程 1 : signal SIGABRT error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28597152/