开发者

UITableview strange behaviour

开发者 https://www.devze.com 2023-03-11 11:46 出处:网络
I have a UITableView with a top navigation bar. The data for the UITableView comes from an array which contains more than 20 objects.

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:(UITableVie开发者_运维知识库w *)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.

UITableview strange behaviour

Help would be greatly appreciated


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号