2012-12-21 81 views
0

我试图创建一个TableView中,把在从NSArray中的数据。不过,我收到此错误:的TableView - 信号SIGABRT

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 

我真的不知道什么代码是导致此,所以我就附​​上两个表方法:NSArray中的

- (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; 
} 

创建:

@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]; 
} 
+2

你有' - (NSInteger的)numberOfSectionsInTableView:(UITableView的*)的tableView'方法在你的代码? –

+1

不,我不这样做,而是根据[AppCoda(http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/),它的工作原理没有它 –

+0

是如果它不是一个分组tableview你可能不需要它,否则'返回整数' –

回答

3

您无法正确设置表格视图的数据源。这使得被发送到了错误的对象tableView:numberOfRowsInSection消息,UIView,因为它从出现错误消息:

[UIView tableView:numberOfRowsInSection:] 

评论/张贴在那里你设置你UITableViewdataSource属性来找出什么是错的代码。你很可能传递了错误的对象。

的数据源是在非常对象的类定义- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section按您的文章。

+0

我只是使用图形用户界面生成器来CTRL-拖动TableView到ViewController。我已经将NSArray对象添加到线程 –

+0

您在哪里定义'tableView numberOfRowsInSection'?那就是要实例化为一个数据源的类...你能说明你对SimpleTableController做了什么,以及如何实例化表视图? – sergio

0
在您的.h文件中

使用下面的代码

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> 

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

在你的.m文件

@implementation ViewController 
@synthesize your_Table; 

Xib文件连接DelegatedataSourceFileowner

ViewDidLoad它分配编程

your_Table.delegate=self; 
your_table.dataSuorce=self; 

使用此

- (NSInteger)tableView:(UITableView *)myTableView numberOfRowsInSection:(NSInteger)section { 
    return [tableData count]; 
} 

后希望它会帮助你。

如果没有,那么从后.h文件中您的代码。