首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TableView -信号信号

TableView -信号信号
EN

Stack Overflow用户
提问于 2012-12-21 22:57:55
回答 2查看 1.2K关注 0票数 0

我正在尝试创建一个TableView并输入来自NSArray的数据。然而,我得到了这个错误:

代码语言:javascript
复制
2012-12-21 15:53:10.239 Arr[13219:c07] -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x71ccb60
2012-12-21 15:53:10.240 Arr[13219:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x71ccb60'
*** First throw call stack:
(0x1c90012 0x10cde7e 0x1d1b4bd 0x1c7fbbc 0x1c7f94e 0x1f96e8 0x1fc3c4 0xc0fa2 0xc092c 0xc4426 0xc90ce 0x6592d 0x10e16b0 0x228cfc0 0x228133c 0x228ceaf 0x1048cd 0x4d1a6 0x4bcbf 0x4bbd9 0x4ae34 0x4ac6e 0x4ba29 0x4e922 0xf8fec 0x45bc4 0x45dbf 0x45f55 0x4ef67 0x12fcc 0x13fab 0x25315 0x2624b 0x17cf8 0x1bebdf9 0x1bebad0 0x1c05bf5 0x1c05962 0x1c36bb6 0x1c35f44 0x1c35e1b 0x137da 0x1565c 0x1c2d 0x1b55 0x1)
libc++abi.dylib: terminate called throwing an exception

我真的不确定是什么代码导致了这种情况,所以我只附加了两个table方法:

代码语言:javascript
复制
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    return cell;
}

创建NSArray:

代码语言:javascript
复制
@implementation ArrViewController {
    NSArray *tableData;
}

@synthesize itemTxt = _itemTxt;
@synthesize itemsLabel = _itemsLabel;
@synthesize model = _model;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-21 23:06:15

您没有正确设置表视图的数据源。这会使tableView:numberOfRowsInSection消息被发送到错误的对象,即错误消息中显示的UIView

代码语言:javascript
复制
 [UIView tableView:numberOfRowsInSection:]

查看/发布设置UITableViewdataSource属性的代码,以找出错误所在。您可能传入了错误的对象。

数据源就是您根据您的帖子在其类中定义- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section的对象。

票数 3
EN

Stack Overflow用户

发布于 2012-12-21 23:12:22

在.h文件中使用以下代码

代码语言:javascript
复制
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *your_Table;

在.m文件中

代码语言:javascript
复制
@implementation ViewController
@synthesize your_Table;

Xib文件中,将DelegatedataSource连接到Fileowner

或者在ViewDidLoad中以编程方式分配它。

代码语言:javascript
复制
your_Table.delegate=self;
your_table.dataSuorce=self;

在那之后,使用这个

代码语言:javascript
复制
- (NSInteger)tableView:(UITableView *)myTableView numberOfRowsInSection:(NSInteger)section {
    return [tableData count];
}

希望能对你有所帮助。

如果没有,那么从.h文件中发布你的代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13992338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档