尝试实现 table 视图并获取线程 1:信号 SIGABRT 错误?
Trying to implement table view and getting Thread 1: signal SIGABRT error?
我一直在尝试在 Xcode 中实现一个简单的 table 视图。但是我 运行 进入这个错误:
[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
如果您需要更多信息,我很乐意为您提供。谢谢
您似乎已将 table 视图的委托 属性 拖到 UIView 而不是 UiViewController 上。
在情节提要中确保将委托 属性 拖到控制器(视图顶部的黄色圆圈)。
我一直在尝试在 Xcode 中实现一个简单的 table 视图。但是我 运行 进入这个错误:
[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
如果您需要更多信息,我很乐意为您提供。谢谢
您似乎已将 table 视图的委托 属性 拖到 UIView 而不是 UiViewController 上。
在情节提要中确保将委托 属性 拖到控制器(视图顶部的黄色圆圈)。