-4
#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 测试[438:207]-[UIView tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例 0x6855500
2012-04-27 13:33:23.362 tableview 测试[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) terminate called throwing an exceptionCurrent language: auto; 目前是objective-c (gdb)

4

3 回答 3

0

我想你错过了UITableViewDelegate

于 2012-11-27T10:43:42.013 回答
0

@interface 表视图:UIViewController....

而不是 UIViewController 尝试使用 UIView

于 2012-07-03T05:43:41.327 回答
-1

您的代码现在不完整。您的“tableView”不是真正的 UITableView,它是 UIViewController!

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

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

于 2012-04-27T14:51:36.340 回答