Neelesh
Neelesh

Reputation: 3693

UITableview strange behaviour

I have a UITableView with a top navigation bar. The data for the UITableView comes from an array which contains more than 20 objects.

Everything is fine so far. However sometimes when i do repeated scrolling (fast), I find last row being repeated, sometimes gets cut into half, overwritten.

I am new to iPhone development and have no clue why this happens.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [appDelegate.preList count];
}

// Customize the appearance of table view cells. 
- (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];
    }

    // Configure the cell...
    Item *i=[appDelegate.preList objectAtIndex:indexPath.row];
    cell.textLabel.text=i.iName;
    cell.accessoryType=UITableViewCellAccessoryNone;
    return cell;
}

I have attached a screenshot of my problem as well. Notice how the navigation bar and the last cell are.

screenshot

Help would be greatly appreciated

Upvotes: 0

Views: 235

Answers (2)

Ved
Ved

Reputation: 612

I think you are seeing this when scrolling fast because only then the tableView bounces leaving some content offset. You have probably added 2 tableViews back to back.

Upvotes: 0

coneybeare
coneybeare

Reputation: 33101

This looks like you have added two identical table views to your view. If you place a break point on numberOfSections… and then inspect the tableView object, I bet you will find two different table views. Start by looking for places in your code where you [self.view addSubview:tableView] or something similar. Remember, if you are using IB to setup your table, you do not need to programmatically add it.

Upvotes: 3

Related Questions