The path of IOS development--Weibo "more" page _ios

Source: Internet
Author: User
Tags first row

Final Effect Diagram:



Moreviewcontroller.m

MOREVIEWCONTROLLER.M//20_ handsome no Weibo////Created by Beyond on 14-8-4. Copyright (c) 2014 Com.beyond.
All rights reserved. #import "MoreViewController.h" @interface Moreviewcontroller () {//More.plist root is a dictionary with two pairs of key value, of which a pair is ZH_CN, and the corresponding value is a number
Group, the length of the array is the number of groupings, each element of the array is also an array,//by different groupings, consisting of an array of Nsarray *_groups;
  @end @implementation Moreviewcontroller-(void) viewdidload {[Super viewdidload];
  
  Log (@ "View%@", Nsstringfromcgrect (Self.view.frame));
  
  1. Set the setting button on the right above the navigation bar [self setrightbarbuttonitem];
  
  2. Load more.plist [self loadplistofmore];

  3. Set TableView global background [self SETTABLEVIEWGLOBALBG];
4. Add the Exit button to the bottom of the TableView tablefooterview [self addeixtbtnatbottom]; //1, set the button to the right above the navigation bar-(void) Setrightbarbuttonitem {self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc]
initwithtitle:@ "Settings" Style:uibarbuttonitemstyleplain target:self action: @selector (settings)]; }//2, Load more.plist file-(void) Loadplistofmore {nsurl *url = [[NsbunDle Mainbundle] urlforresource:@ "More" withextension:@ "plist"];
An array of grouped, grouped members, that is, an array of rows consisting of _groups = [nsdictionary dictionarywithcontentsofurl:url][@ "ZH_CN"]; }//3, set TableView global background-(void) SETTABLEVIEWGLOBALBG {//clear extra white space on top of TableView in iOS 7 Self.automaticallyadjustsscrol
  Lviewinsets = NO; Set ScrollView additional scrolling area//Self.tableView.contentInset = Uiedgeinsetsmake (< #CGFloat top#> < #CGFloat left#> , < #CGFloat Bottom#&gt, < #CGFloat right#>)//Important ~ When the TableView style is group, if you want to change the background, you must first clear the stripe-like self-band Backgroundview,
  Then you can set the background color of the tableview Self.tableView.backgroundView = nil;
  
  Self.tableView.backgroundColor = KGLOBALBG;
  Reduce the spacing between each group Self.tableView.sectionHeaderHeight = 0;
Self.tableView.sectionFooterHeight = 5; //4, create an Exit button and add to the bottom of the TableView Tablefooterview-(void) Addeixtbtnatbottom {//1, create a footerview, and use it as TableView Tablefo
  Oterview UIView *footerview = [[UIView alloc] init]; The width of the TableView Tablefooterview is 320, only highly adjustable footerview. frame = CGRectMake (0, 0, 320, 60); Just create the Footerview as a tableview tablefooterview to prevent users from clicking on the bottom Dockitem accidentally point to the exit button, so to set an extra space,


  
  
  Add tablefooterview width fixed is the Self.tableView.tableFooterView = Footerview;
  2, create the Exit button and add to the bottom of the TableView tablefooterview uibutton *btnexit = [UIButton buttonwithtype:uibuttontypecustom]; Footerview is a tableview tablefooterview existence, the button is added to the Footerview inside, where the button's frame x Y 5 is relative to the footerview Btnexit.frame =
  CGRectMake (10, 5, 300, 40);
  The font size on the button BtnExit.titleLabel.font = [Uifont systemfontofsize:17];
  
  Button's Listener click event [Btnexit addtarget:self Action: @selector (Exitbtnclick) forcontrolevents:uicontroleventtouchupinside];
  The classification method, sets the button normal and highlights when the background picture (can stretch) [Btnexit setbtnbgimgfornormalandhighightedwithname:@ "Common_button_red.png"];
  Sets the text on the button, the last group, the array has only one row, each row is a dictionary nsstring *btntitle = [_groups lastobject][0][@ "name"];
  
  
  
  [Btnexit Settitle:btntitle Forstate:uicontrolstatenormal]; 3, the most important step, add the Exit button you just created to the TableView Tablefooterview//[Footerview Addsubview:btnexit];

[Self.tableView.tableFooterView Addsubview:btnexit]; //Response Click Set Click event-(void) Settings {log (@ "Click the Set Button");//Click exit button-(void) Exitbtnclick {//Cancelbuttontitle black//D Estructivebuttontitle Red//otherbuttontitles gray-white uiactionsheet *actionsheet = [[Uiactionsheet alloc] initWithTitle:@ " Are you sure you quit this account?
  
  "Delegate:nil cancelbuttontitle:@" Cancel "destructivebuttontitle:@" "Red" otherbuttontitles:@ "other", nil];
Uiactionsheet is best to display to window above, so not afraid of point, because sometimes the controller's view does not necessarily occupy the entire window size [actionsheet ShowInView:self.view.window]; //Click the Set button-(void) Setting {log (@ "Settings")}//proxy method, click on a row call-(void) TableView: (UITableView *) TableView Didselectrowat

Indexpath: (Nsindexpath *) Indexpath {[TableView deselectrowatindexpath:indexpath animated:yes];}
  #pragma mark-Data source method//Total number of groups The last group is a special exit button, so do not enter the Recycle-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {
return _groups.count-1; ///The number of rows per group-(Nsinteger) TableView: (UITableView *) TableView numberofrowsInsection: (Nsinteger) Section {//Get an array of each row Nsarray *rows = _groups[section];
Returns the number of rows for this group return rows.count; ///each row of each group displays unique content-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *)
  Indexpath {static NSString *cellid = @ "Beyond";
  1. First get the cell UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellid] in the pool; If empty, create a new if (cell = = nil) {//Create a new cell cell = [[UITableViewCell alloc] initwithstyle:uitableviewcellstyled
    Efault Reuseidentifier:cellid];
    1.1. Clear the background of the text label cell.textLabel.backgroundColor = [Uicolor Clearcolor];
    
    1.2. Set the text label highlighted when the text color is also the default text color (do not let it color) Cell.textLabel.highlightedTextColor = Cell.textLabel.textColor;
    1.3. Focus, when created, initialize the background view of the cell and select the background view uiimageview *bgimgview = [[Uiimageview alloc] init];
    
    Cell.backgroundview = Bgimgview;
    Uiimageview *selectedbgimgview = [[Uiimageview alloc] init];
  Cell.selectedbackgroundview = Selectedbgimgview; }
  2. Set the cell unique content//set the caption text shown in the group--> the first few lines---> Dictionary cell.textLabel.text = _groups[indexpath.section][indexpath.ro
  
  w][@ "Name"];
  3. Set the background picture of the cell//first remove the cell background view Uiimageview *bgimgview = (Uiimageview *) Cell.backgroundview;
  
  Uiimageview *selectedbgimgview = (Uiimageview *) Cell.selectedbackgroundview;
  The background image file name//of the cell is divided into the group Nsarray *rows = _groups[indexpath.section] by the array of each row;
  To get the group, the Total row number int rownum = Rows.Count;
  
  NSString *name = nil;
  if (rownum = = 1) {//If the group is only one row, use the four corners of the picture name = @ "Common_card_background.png";
  else if (Indexpath.row = 0) {//If there are more than one row in the group, and the current row is the first row of the group, the picture name = @ "Common_card_top_background.png" with the upper half rounded; else if (Indexpath.row = = rowNum-1) {//If there are more than one row for the group, and the current row is the last row of the group, the picture name = @ "With the bottom half rounded to the corner" common_card_bottom_backg
  Round.png ";
  else {//middle///If there are more than one row in the group, and the current row is not in the first row of the group and not the last line of the group, use the four-week-round picture name = @ "Common_card_middle_background.png"; //Set the cell's normal and selected background picture bgimgview.image = [Uiimage Imagestretchedwithname:name]; Selectedbgimgview.image = [UIImage imagestretchedwithname:[name filenameinsertsuffixbeforeextension:@ "_highlighted
  
  "]]; 4. Set the rightmost arrow indicator, divided text and picture two kinds of situations to discuss if (Indexpath.section = 2) {//If the 2nd group, then display the text, "Reading mode-Theme" Uilabel *label = [[Uila
    Bel Alloc] init];
    Clear the label background color label.backgroundcolor = [Uicolor Clearcolor];
    Label text Size Label.font = [Uifont systemfontofsize:13];
    Label text color Label.textcolor = [Uicolor Graycolor];
    Label text on the right label.textalignment = nstextalignmentright;
    The width-height label.bounds = cgrectmake (0, 0, 100, 30) of the label frame; The 1th row of the group shows "graph mode" and line 2nd shows "Classic theme" Label.text = (Indexpath.row = 0)?
    @ "Map Mode": @ "Classic theme";
  Finally, the custom rightmost view is set to the satellite view Cell.accessoryview = label of the cell; else {//If it is another group, display the picture arrow to the right Cell.accessoryview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "common
  _icon_arrow.png "]];
}//5. Return to cell returned cell;
 } @end

The data source for the "more" page more.plist


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.