简体   繁体   中英

ios, UITableView, indent changed unexpectedly after scrolling

I have a problem with indention in UITableView . See image to make it clear .

在此处输入图片说明

There are just cell with UILabel . After launching app, all points have the same indention (like points Schedule & Favourites on picture). But when I scroll it up & then scroll it down back, the indention of labels changes. It appeared in iOS6 as well as in iOS7 .

Does anybody have ideas how to fix it?

EDIT0: It seems than only first rendering (before screen is appeared) works well. All others calls "cellForRowAtIndexPath" return incorrect cell view. Might be it connected w/ constraints... but i'm not sure.
Anyway the way are supposed by NSS works. Thanks everybody for your help.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //#warning Incomplete method implementation.
    // Return the number of rows in the section.

    return [activeList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"mainPointCell";
    OMSMainActiveCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    [cell.textLabel setText:[activeList objectAtIndex:indexPath.row]];

    return cell;
}

Add following code in your custom cell class ie in OMSMainActiveCell

- (void) layoutSubviews 
  {
      [super layoutSubviews];
      self.textLabel.frame = CGRectMake(0, 0, 320, 20);
  }

Also you can see this answer .

Hope this helps you.

Try to set frame of your label like

[label setFrame:CGRectMake(cell.frame.origin.x , cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];

if still its happening then let us know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM