SimpleTable练习引发的异常错误

时间:2014-05-15 16:23:04

标签: uitableview

我收到有关发送给选择器的错误消息的错误,但无法弄清楚:

2014-05-15 09:13:41.064 SimpleTable[4364:60b] The tableData array contains (
    "Item 0",
    "Item 1",
    "Item 2",
    "Item 3",
    "Item 4",
    "Item 5",
    "Item 6",
    "Item 7",
    "Item 8",
    "Item 9"
)
2014-05-15 09:13:41.101 SimpleTable[4364:60b] -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8fb1290
2014-05-15 09:13:41.113 SimpleTable[4364:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8fb1290'

这是.h文件:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDelegate>

@property (nonatomic, strong) NSMutableArray *tableData; // holds the table data
@property (nonatomic) int cellCount;

@end

这是.m文件:

 #import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize tableData;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // Create the array to hold the table data
    self.tableData = [[NSMutableArray alloc] init];

    // Create and add 10 data items to the table data array
    for (NSUInteger i = 0; i < 10; i++) {

        // The cell will contain a string "Item X"
        NSString *dataString = [NSString stringWithFormat:@"Item %d", i];

        // Here the new string is added to the end of the array
        [self.tableData addObject:dataString];
    }
    // Print out the contents of the array into the log
    NSLog(@"The tableData array contains %@", self.tableData);
}

-(void)viewDidUnload
{
    [super viewDidUnload];
    self.tableData = nil;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

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

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

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


    }
    return cell;
}

@end

0 个答案:

没有答案
相关问题