IOS8 UITableView split bar setting separator intent = 0 does not work

Source: Internet
Author: User

IOS8 UITableView split bar setting separator intent = 0 does not work

When ios7 is used, separator intend = 0 of TableView can be set on storyboard to pin the split entries of tableview to the header.

However, when ios8.

Google found the answer in stackoverflow

Translation record

IOS8 introduces the layoutMargins attribute in cell and tableview, and this attribute does not exist in iOS 7, so you need to treat the two versions differently.

Use the Ricky solution to set the layoutMargin attribute in the cell:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {        [cell setSeparatorInset:UIEdgeInsetsZero];    }    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {        [cell setLayoutMargins:UIEdgeInsetsZero];    }

// Add the following paragraph according to the author's final meaning.

If ([cell respondsToSelector: @ selector (setPreservesSuperviewLayoutMargins :)]) {

[Cell setPreservesSuperviewLayoutMargins: NO];

}

}

You also need to set the same attribute in tableview. through multiple experiments, I found that you can set this attribute in viewDidLayoutSubviews.

Copy the following code to your view implementation.

-(void)viewDidLayoutSubviews{    [super viewDidLayoutSubviews];    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {        [self.tableView setSeparatorInset:UIEdgeInsetsZero];    }    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {        [self.tableView setLayoutMargins:UIEdgeInsetsZero];    }} 

In this way, you can split the headers in ios7 and iOS 8. Ios6 is the top header by default, so this solution can be applied to ios6-8 ).

Edit: According to @ bffmike on Twitter, you may also need to set preservesSuperviewLayoutMargins = NO in the cell. Note that the situation varies from person to person.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.