Solve the problem of UITableView in the top of Uinavigationcontroller in IOS7

Source: Internet
Author: User

Solve the problem of UITableView in the top of Uinavigationcontroller in IOS7

When the problem occurs:

Source:

class to use:

Uiviewcontroller+titletextattributes.h and UIVIEWCONTROLLER+TITLETEXTATTRIBUTES.M

////Uiviewcontroller+titletextattributes.h//youxianming////Created by youxianming on 14-9-20.//Copyright (c) 2014 youxianming. All rights reserved.//#import<UIKit/UIKit.h>#import "NCTitleAttribute.h"@interfaceUiviewcontroller (titletextattributes)/** * Set Title property of current Controller * * @param attribute Property Object*/- (void) Titletextattributes: (Nctitleattribute *) attribute;@end
////UIVIEWCONTROLLER+TITLETEXTATTRIBUTES.M//youxianming////Created by youxianming on 14-9-20.//Copyright (c) 2014 youxianming. All rights reserved.//#import "Uiviewcontroller+titletextattributes.h"@implementationUiviewcontroller (titletextattributes)#pragmamark-public-(void) Titletextattributes: (Nctitleattribute *) attribute{[self controller:self titletextattributes:[attribute transformtodictionary];}#pragmamark-private-(voidController: (Uiviewcontroller *) controller titletextattributes: (nsdictionary *) dictionary{if([Controller Iskindofclass:[uiviewcontrollerclass]]) {[Controller.navigationController.navigationBar settitletextattributes:dictionary]; }}@end

NCTitleAttribute.h and NCTITLEATTRIBUTE.M

////NCTitleAttribute.h//youxianming////Created by youxianming on 14-9-20.//Copyright (c) 2014 youxianming. All rights reserved.//#import<Foundation/Foundation.h>@interfaceNctitleattribute:nsobject@property (nonatomic, strong) Uicolor*titlecolor;//Title Color@property (nonatomic, strong) Uifont *titlefont;//Title Font@property (nonatomic, strong) Uicolor*shadowcolor;//Shadow color@property (nonatomic, assign) Cgsize Shadowoffset;//Shadow offset//To convert a parameter to a dictionary-(Nsdictionary *) transformtodictionary;@end
////NCTITLEATTRIBUTE.M//youxianming////Created by youxianming on 14-9-20.//Copyright (c) 2014 youxianming. All rights reserved.//#import "NCTitleAttribute.h"@implementationNctitleattribute-(Nsdictionary *) transformtodictionary{nsmutabledictionary*dic = [NsmutabledictionaryNew]; if(_titlecolor) {[dic setobject:_titlecolor forkey:nsforegroundcolorattributename]; }    Else{[dic setobject:[uicolor Blackcolor] forkey:nsforegroundcolorattributename]; }        if(_titlefont) {[dic setobject:_titlefont forkey:nsfontattributename]; }        if(_shadowoffset.height &&_shadowoffset.width) {Nsshadow*shadow = [NsshadowNew]; Shadow.shadowcolor=_shadowcolor; Shadow.shadowoffset=_shadowoffset;    [DiC Setobject:shadow Forkey:nsshadowattributename]; }        returnDiC;}@end

Controller Source:

////VIEWCONTROLLER.M//Uirectedgenone////Created by youxianming on 14/10/29.//Copyright (c) 2014 youxianming. All rights reserved.//#import "ViewController.h"#import "Uiviewcontroller+titletextattributes.h"#import "NCTitleAttribute.h"#import "WxHxD.h"@interfaceViewcontroller () <uitableviewdatasource, uitableviewdelegate>@property (nonatomic, strong) UITableView*TableView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //Initialize title[self inittitle]; //Background ViewUIView *backview =[[UIView alloc] Initwithframe:cgrectmake (0, [WxHxD statusbarandnavigationbarheight], [WxHxD ScreenWidth], [WxHxD ScreenHeight]-[WxHxD statusbarandnavigationbarheight]); BackView.layer.borderWidth=2. F; BackView.layer.borderColor=[Uicolor Redcolor].    Cgcolor;        [Self.view Addsubview:backview]; //TableView_tableview =[[UITableView alloc] InitWithFrame:backView.bounds style:uitableviewstyl    Eplain]; _tableview.Delegate=Self ; _tableview.datasource=Self ;    [Backview Addsubview:_tableview]; }- (void) Inittitle {self.title=@"youxianming"; Nctitleattribute*nctitle = [NctitleattributeNew]; Nctitle.titlecolor=[Uicolor Redcolor]; Nctitle.titlefont= [Uifont fontwithname:@"Helveticaneue-thin"Size -. f]; [Self titletextattributes:nctitle];}#pragmaMark-Agent-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return 7;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {StaticNSString *reusedflag =@"youxianming"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:reusedflag]; if(Cell = =Nil) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifi    Er:reusedflag]; } Cell.textLabel.font= [Uifont fontwithname:@"Helveticaneue-thin"Size -. f]; Cell.textLabel.text=@"no Zuo no die"; Cell.textLabel.textColor=[Uicolor Graycolor]; returncell;}@end

How to solve it? Very simple:

Add the following code:

// Let the edge remain white empty

float systemversion = [[[uidevice currentdevice] systemversion] Floatvalue];

if (systemversion >= 7.0) {

self. Edgesforextendedlayout = uirectedgenone;

}

Effect:

Note: This type of problem only appears if it is above iOS7

Solve the problem of UITableView in the top of Uinavigationcontroller in IOS7

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.