iOS development, UITableView related issues
Last Update:2017-05-16
Source: Internet
Author: User
<span id="Label3"></p><span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">article one: settings for UITableViewCell content</span></span>The text is put to the last nsindexpath *indexpath = [nsindexpath indexpathforrow:_dataarr.count-1 insection:0]; [_tableview Scrolltorowatindexpath:indexpath Atscrollposition:uitableviewscrollpositionbottom animated:YES]; Refreshes the specified Cellnsindexpath *indexpath_3=[nsindexpath indexpathforrow:0 insection:2]; Nsarray *indexarray3=[nsarray arraywithobject:indexpath_3]; [self.tableview Reloadrowsatindexpaths:indexarray3 withrowanimation:uitableviewrowanimationautomatic];<span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">the second section: the left part of the UITableViewCell split line is missing some workarounds</span></span>-(void) viewdidlayoutsubviews {if ([self.tableview respondstoselector: @selector (setseparatorinset:)]) {[ Self.tableview setseparatorinset:uiedgeinsetszero]; } if ([self.tableview respondstoselector: @selector (setlayoutmargins:)]) {[self.tableview setlayoutmargins:uiedgeins etszero]; }}-(void) tableView: (uitableview *) tableView willdisplaycell: (uitableviewcell *) cell Forrowatindexpath: (nsindexpath *) indexpath{if ([cell respondstoselector: @selector (setlayoutmargins:)]) {[cell setlayoutmargins:uiedgeinsetszero] ; } if ([cell respondstoselector: @selector (setseparatorinset:)]) {[cell setseparatorinset:uiedgeinsetszero]; }}<span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">article three: UITableView the split line part does not show the problem?</span></span>simulator, debug, optimize rendering for window scale cancel Tick.<span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">Fourth: The two methods used to customize cell dividing line roughly</span></span>a, the custom split line as a view on the cell contentview, it is important to pay attention to the reuse problem, so this view should be added when the cell is Initialized. The sample code is as Follows:<style><style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 }p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae }p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3e1e81 }p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000; min-height: 21.0px }p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1e9421 }span.s1 { }span.s2 { color: #6122ae }span.s3 { color: #000000 }span.s4 { color: #c42275 }span.s5 { color: #c81b13 }span.s6 { color: #703daa }span.s7 { color: #3e1e81 }span.s8 { color: #0435ff }</style></style><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">-(<span class="s2">UITableViewCell<span class="s1"> *) tableView: (<span class="s2">uitableview<span class="s1"> *) tableView cellforrowatindexpath: (<span class="s2">nsindexpath <span class="s1"> *) indexpath{</span> </span> </span> </span> </span> </span></span></p></p><p class="p2"><p class="p2"><span class="s3" style="font-size: 14px"><span class="s1">UITableViewCell<span class="s3"> *cell =<span class="s4">nil<span class="s3">;</span> </span> </span> </span></span></p></p><p class="p3"><p class="p3"><span class="s3" style="font-size: 14px">Cell = [tableView <span class="s1">dequeuereusablecellwithidentifier<span class="s3">:<span class="s5">@ "cell"<span class="s3">];</span> </span> </span> </span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px"><span class="s4">if<span class="s1"> (cell = =<span class="s4">Nil<span class="s1">) {</span> </span> </span> </span></span></p></p><p class="p3"><p class="p3"><span class="s3" style="font-size:14px"> cell= [[<span class=" s2 "> Uitableviewcell<span class="s3"> <span class="s1">alloc<span class="s3">]<span class="s1">initwithstyle <span class="s3">:<span class="s1">uitableviewcellstylesubtitle<span class="s3"> <span class="s1"> Reuseidentifier<span class="s3">:<span class="s5">@ "cell" <span class="s3">]; </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></p></p><p class="p3"><p class="p3"><span class="s3" style="font-size: 14px">Cell. <span class="s6">Accessoryview<span class="s3"> = [[<span class="s2">uiimageview<span class="s3"> <span class="s1">alloc<span class="s3">]<span class="s1">initwithimage<span class="s3">: [<span class="s2">UIImage<span class="s3"> <span class="s1"> Imagenamed<span class="s3">:<span class="s5">@ "huicellacce"<span class="s3">]; </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">Cell. <span class="s6">backgroundcolor<span class="s1"> = [<span class="s2">uicolor<span class="s1"> <span class="s7">clearcolor<span class="s1">];</span> </span> </span> </span> </span> </span></span></p></p><p class="p5"><p class="p5"><span class="s3" style="font-size: 14px"><span class="s1">//cell.selected = YES;</span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px"><span class="s2">uiimageview<span class="s1"> *imageviewsepe = [[<span class="s2">uiimageview<span class="s1"> <span class="s7">alloc<span class="s1">]<span class="s7">initwithframe<span class="s1">:<span class="s7">cgrectmake <span class="s1"> (+,<span class="s8"><span class="s1"> <span class="s8"><span class="s1"> <span class="s8"><span class="s1"> <span class="s8">1<span class="s1">)];</span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">Imageviewsepe. <span class="s6">image<span class="s1"> = [<span class="s2">UIImage<span class="s1"> <span class="s7">imagenamed<span class="s1">:<span class="s5">@ "godline"<span class="s1">];</span> </span> </span> </span> </span> </span> </span></span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">[cell. <span class="s6"> Contentview<span class="s1"> <span class="s7">addsubview<span class="s1">: imageviewsepe];</span> </span> </span> </span> </span> <span class="s1" style="font-size: 14px"> </span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">}</span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px"><span class="s4">return<span class="s1"> cell;</span> </span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">}</span></p></p><span><span><span> </span></span></span>b, more complex, The use of the underlying framework<style><style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 }p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3e1e81 }span.s1 { }span.s2 { color: #c42275 }span.s3 { color: #703daa }span.s4 { color: #000000 }span.s5 { color: #6122ae }span.s6 { color: #3e1e81 }span.s7 { color: #0435ff }span.s8 { color: #1e9421 }span.s9 { font: 18.0px "PingFang SC"; color: #1e9421 }</style></style><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">-(<span class="s2">void<span class="s1">) drawrect: (<span class="s3">cgrect<span class="s1">) rect {</span> </span> </span> </span></span></p></p><p class="p2"><p class="p2"><span class="s4" style="font-size: 14px"><span class="s3">cgcontextref<span class="s4"> context = <span class="s1">uigraphicsgetcurrentcontext<span class="s4">();</span> </span> </span> </span></span></p></p><p class="p2"><p class="p2"><span class="s4" style="font-size: 14px"><span class="s1">cgcontextsetfillcolorwithcolor<span class="s4">(context, [<span class="s5">uicolor<span class="s4"> <span class="s1">clearcolor<span class="s4">]. <span class="s3"> Cgcolor<span class="s4">); <span class="s1">cgcontextfillrect<span class="s4">(context, rect);</span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></p></p><p class="p2"><p class="p2"><span class="s4" style="font-size: 14px"><span class="s1">cgcontextsetstrokecolorwithcolor<span class="s4">(context, [<span class="s5">uicolor<span class="s4"> <span class="s1">blackcolor<span class="s4">]. <span class="s3"> Cgcolor<span class="s4">);</span> </span> </span> </span> </span> </span> </span> </span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px"><span class="s6">cgcontextstrokerect<span class="s1">(context, <span class="s6">cgrectmake<span class="s1">(<span class="s7">5<span class="s1">,-<span class="s7">1<span class="s1">, rect.<span class="s3">size<span class="s1">. <span class="s3"> Width<span class="s1"> - <span class="s7"><span class="s1"> <span class="s7">1<span class="s1">));<span class="s8" style="font-size: 12px"> //down Split Line<span class="s9"><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p></p><p class="p2"><p class="p2"><span class="s4" style="font-size: 14px"><span class="s1">cgcontextsetstrokecolorwithcolor<span class="s4">(context, [<span class="s5">uicolor<span class="s4"> <span class="s1">bluecolor<span class="s4">]. <span class="s3"> Cgcolor<span class="s4">);</span> </span> </span> </span> </span> </span> </span> </span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px"><span class="s6">cgcontextstrokerect<span class="s1">(context, <span class="s6">cgrectmake<span class="s1">(<span class="s7">5<span class="s1">, rect.<span class="s3">size<span class="s1">. <span class="s3"> Height<span class="s1">, rect.<span class="s3">size<span class="s1">. <span class="s3"> Width<span class="s1"> - <span class="s7">ten<span class="s1">,<span class="s7">1<span class="s1">));</span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></p></p><p class="p1"><p class="p1"><span class="s1" style="font-size: 14px">}</span></p></p><span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">fifth: The code of the way to customize the cell, must write Initwithstyle method</span></span>-(id) initwithstyle: (uitableviewcellstyle) style reuseidentifier: (nsstring*) reuseidentifier{ Self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { & nbsp /*** write here to add controls ***/ } return self;} iOS Development TableView Tabelview custom cell The first: by creating a xib File. ① first create the Xib file ② create a xib file corresponding to the model a, the same name as the Xib file, and inherit the UITableViewCell class, and implement the Cellwithtableview construction Method. ③ Change the default class for xib files in interface builder, the model class created for the second Step. ④ creates the data Model b, and a contains the data model B ⑤a assigns a value to the control by lazy loading the B method (that is, by overriding the setter method of the B object). second type: code customization Cell ① Create a new class that inherits uitableviewcell, which has a frame model ② rewrite initwithstyle: Reuseidentifier: method (add All the child controls that need to be displayed (you do not need to set the child Control's data and frame, child controls to add to contentview, and add property settings). ③ building a data model ④ establishes a frame model (owning a data Model) ⑤ overrides the setter method of the data model object, then sets the control size, and the cell height. The ⑥ controller has an array of frame Objects. When the cell is in trouble, assign it directly to the Cell.frame Object. <span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">sixth: iOS development-let tableview not pull the refresh, can pull up load</span></span>1. Follow the proxy UIScrollViewDelegate2 First. implement the proxy method-(void) scrollviewdidscroll: (uiscrollview*) scrollview{if ( Tabelview.contentoffset.y <= 0) {tabelview.bounces = NO; }else {tabelview.bounces = YES; }}<span style="background-color: #ffff00; color: #ff0000"><span style="background-color: #ffff00; color: #ff0000">seventh: Remove the UITableView bottom excess line and split line</span></span>Self.tableView.tableFooterView = [[UIView alloc] initwithframe:cgrectzero];<p><p>iOS development, UITableView related issues</p></p></span>