程序接收信号SIGABRT(xcode)

时间:2012-04-27 08:06:51

标签: iphone objective-c ios4

#import <UIKit/UIKit.h>

@interface tableview : UIViewController<UITableViewDataSource>

{
    NSArray *listOfItems;
}
@property(nonatomic,retain) NSArray *listOfItems;

@end


#import "tableview.h"

@implementation tableview
@synthesize listOfItems;

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

    //NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
    cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    listOfItems = [[NSArray alloc] initWithObjects:@"first",@"second",@"third", nil];

    //listOfItems = [[NSMutableArray alloc]init];
   // [listOfItems addObject:@"first"];
    //[listOfItems addObject:@"second"];
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)dealloc
{
    [listOfItems release];
    [super dealloc];
}



@end
  

2012-04-27 13:33:23.276 tableview test [438:207] - [UIView tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x6855500
  2012-04-27 13:33:23.362 tableview test [438:207] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:
  ' - [UIView tableView:numberOfRowsInSection:]:无法识别的选择器
  发送到实例0x6855500'
      *
首先抛出调用堆栈:
      (0x13bb052 0x154cd0a 0x13bcced 0x1321f00 0x1321ce2 0x1ecf2b 0x1ef722 0x9f7c7 0x9f2c1 0xa228c 0xa6783 0x51322 0x13bce72 0x1d6592d   0x1d6f827 0x1cf5fa7 0x1cf7ea6 0x1d8330c 0x23530 0x138f9ce 0x1326670   0x12f24f6 0x12f1db4 0x12f1ccb 0x12a4879 0x12a493e 0x12a9b 0x2282   0x21f5)       终止调用抛出异常当前语言:auto;目前objective-c(gdb)

3 个答案:

答案 0 :(得分:0)

@interface tableview:UIViewController ....

而不是UIViewController尝试使用UIView

答案 1 :(得分:0)

我认为你错过了UITableViewDelegate

答案 2 :(得分:-1)

您的代码现已完成。你的“tableView”不是真正的UITableView,它是UIViewController!

你应该在你的h文件和xib文件中有UITableView实例,然后将它们相互链接,并将UITableViewDelegate属性设置为你的UIViewcontroller类。

请查看基本的UITableView(或UITableViewController)样本......