Getting error when running app


#1

Application builds & runs fine, I am getting this error when ever i try to insert a task…
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:6246
2013-12-28 13:51:40.120 iTahDoodle[3694:70b] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:’
*** First throw call stack:
any clue?
here is my code:in AppDelegate.m
#pragma mark - Application delegate callback

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //Create an empty array
    self.tasks = [NSMutableArray array];

    //Create intial window
    CGRect winFrame = [[UIScreen mainScreen] bounds];
    UIWindow *theWindow = [[UIWindow alloc]initWithFrame];
    self.window = theWindow;

    //Define the frame rectangle of three UI elements
    //CGRectMake() creates a CGRect from (x, y, width, height)
    CGRect tableFrame = CGRectMake(0,80, winFrame.size.width, winFrame.size.height -100);
    CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
    CGRect buttonFrame = CGRectMake(228,40, 72, 31);

    //Create and configure the UITableVIew instance
    self.taskTable = [[UITableView alloc]initWithFrame:tableFrame
    style:UITableViewStylePlain];

    self.taskTable.separatorStyle = UITableViewCellSeparatorStyleNone;

    // Make the BNRAppDelegate the table view’s dataSource
    self.taskTable.dataSource = self;

    // Tell the table view which class to intantiate whenever it
    // needs to create a new cell
    [self.taskTable registerClass:[UITableViewCell class] forCellReuseIdentifier:@“cell”];

    // Create and configure the UITextField instance where new tasks will be entered
    self.taskField = [[ UITextField alloc] initWithFrame:fieldFrame];
    self.taskField.borderStyle = UITextBorderStyleRoundedRect;
    self.taskField.placeholder = @" Type a task, tap Insert";

    //Creating uibutton
    self.insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.insertButton.frame = buttonFrame;
    // Button tiltle
    [self.insertButton setTitle:@“Insert” forState:UIControlStateNormal];
    // Set the target and action for insert button
    [self.insertButton addTarget:self action:@selector(addTask:)forControlEvents:UIControlEventTouchUpInside];

    // Add UI elements to the view
    [self.window addSubview:self.taskTable];
    [self.window addSubview:self.taskField];
    [self.window addSubview:self.insertButton];

    //Set background color for main frame and make it visable
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;
    }

#pragma mark - Action Methods

  • (void)addTask:(id)sender
    {
    NSString *text = [self.taskField text];
    if ([text length]== 0) {
    return;
    }
    // Add it to the working array
    [self.tasks addObject:text];
    // Refresh the table so that the new item shows up
    [self.taskTable reloadData];

    //Clear text field
    [self.taskField setText:@""];

    // Dismiss the Keyboard
    [self.taskField resignFirstResponder];
    }

#pragma mark - Table view management

  • (NSInteger) tableView:( UITableView *)tableView numberOfRowsInSection:( NSInteger)section
    {
    return [self.tasks count];
    }
  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@“Cell”];
    NSString *item = [self.tasks objectAtIndex:indexPath.row];
    c.textLabel.text = item;
    return c;
    }
    @end

#2

You have registered the UITableViewCell class with a reuse identifier of “cell”, yet in cellForRowAtIndexPath you are dequeueing with a cell identifier of “Cell”.


#3

Great catch! that fixed it.
Thank you so much