ios - 尝试实现 TableView 并获取线程 1 : signal SIGABRT error?

标签 ios objective-c xcode tableview sigabrt

我一直在尝试在 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/

相关文章:

ios - WkWebView 不会加载 HTMLstring

ios - Xcode 5 错误 : Unable to create directory/projectname. build/Objects-normal/i386

ios - Swift:在Swift中应用滤镜时,UIImage方向问题

ios - searchDisplayController' 已弃用 : first deprecated in iOS 8. 0

ios - 多个命令产生与信息 plist 错误相关的路径

ios - Xcode 试图定位或生成匹配的签名 Assets

ios - 使一个 UIView 跟踪另一个约束的动画

ios - 如何为 UITableView 设置边框?

objective-c - SCNView中的撕裂图形

objective-c - objective-c : Sliding?