【问题标题】:Trying to implement table view and getting Thread 1: signal SIGABRT error?尝试实现表视图并获取线程 1:信号 SIGABRT 错误?
【发布时间】:2015-02-19 01:22:01
【问题描述】:

我一直在尝试在 Xcode 中实现一个简单的表格视图。但是我遇到了这个错误:

[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

如果您需要更多信息,我很乐意为您提供。谢谢。

【问题讨论】:

  • 你的方向是正确的。无法识别正在发送的消息。怎么可能?您认为您将 ViewController 设置为 UITableView 的委托,但您必须将其设置为 ViewController 实例以外的其他东西;因此无法识别的选择器崩溃。
  • 表数据源很可能是在情节提要中设置的,指向视图控制器以外的东西。

标签: ios objective-c xcode tableview sigabrt


【解决方案1】:

看起来您已将表格视图的委托属性拖到 UIView 而不是 UiViewController 上。

确保在情节提要中将委托属性拖到控制器(视图顶部的黄色圆圈)。

【讨论】:

  • 现在一切都说得通了。我确实错误地拖动了代理。
猜你喜欢
  • 2012-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-02
相关资源
最近更新 更多