IOS8 UITableView split bar Setting Separator Intent = 0 does not work

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/ljb_wh/article/details/40788333

iOS7 when the storyboard set TableView separator intend = 0 allows the tableview of the split bar to the top of the head.

However, when IOS8 was upgraded, the discovery did not work.

After Google, found the answer in StackOverflow

Translation record

IOS8 introduced the Layoutmargins attribute in both the cell and the TableView, and this attribute is not available in iOS 7, so you need to treat these two versions differently.

Use the Ricky scheme to set the Layoutmargin property 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
    }

//According to the author's final meaning, add the following paragraph

If([cell respondstoselector: @selector(setpreservessuperviewlayoutmargins:)]) {

[Cell Setpreservessuperviewlayoutmargins:no];

}


}

You also need to set the same properties in TableView. Through many experiments, I found that you can set this property in Viewdidlayoutsubviews.

Copy the following code into the implementation of your view

-(void)Viewdidlayoutsubviews
{
[SuperViewdidlayoutsubviews];

If ([Self.TableView Respondstoselector:@selector(Setseparatorinset:)]) {
[Self.TableView Setseparatorinset:Uiedgeinsetszero];
}

If ([Self.TableView Respondstoselector:@selector (setlayoutmargins< Span class= "pun" >:)]) {
        [self. tableview setlayoutmargins: Uiedgeinsetszero];
    } } /span>

In this way, it is possible to achieve the need for split-bar head in Ios7,ios8. (Translator: IOS6 default is the head, so this scheme can be applied to ios6-8).

Edit: As @bffmike says on Twitter, you may also need to set preservessuperviewlayoutmargins=no in the cell. Again: Everyone's situation is different.

IOS8 UITableView split bar Setting Separator Intent = 0 does not work

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.