ios_20_ Weibo "more" page

Source: Internet
Author: User

Eventually:




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, which There is a pair of ZH_CN, the corresponding value is an array, the length of the array is how many groups, each element of the array is an array,//by different groupings, composed of an array of Nsarray *_groups;}    @end @implementation moreviewcontroller-(void) viewdidload{[Super Viewdidload];        Log (@ "View%@", Nsstringfromcgrect (Self.view.frame));        1. Set the Settings button on the right side of the navigation bar [self setrightbarbuttonitem];        2. Load more.plist [self loadplistofmore];    3. Set the global background of the tableview [self SETTABLEVIEWGLOBALBG]; 4. Add the Exit button to the bottom of the TableView tablefooterview [self addeixtbtnatbottom];} 1, set the button on the right side of the navigation Bar-(void) setrightbarbuttonitem{self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] Ini twithtitle:@ "Set" 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 groupings consisting of groups of members that are arrays, and a row of rows consisting of an array of _groups = [nsdictionary dictionarywithcontentsofurl:url][@ "ZH_CN"];} 3, set the global background of the TableView-(void) settableviewglobalbg{//clear the extra empty area at the top of the TableView in iOS 7 Self.automaticallyadjustsscrollvi    Ewinsets = 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 striped Backgroundview,    Then you can set the TableView background color self.tableView.backgroundView = nil;        Self.tableView.backgroundColor = KGLOBALBG;    Narrow the spacing between each group Self.tableView.sectionHeaderHeight = 0; Self.tableView.sectionFooterHeight = 5;} 4, create an Exit button and add to the bottom of TableView tablefooterview-(void) addeixtbtnatbottom{//1, create a footerview,    Use it as the TableView tablefooterview UIView *footerview = [[UIView alloc] init]; The width of the TableView tablefooterview is fixed at 320 and is only highly adjustable footervieW.frame = CGRectMake (0, 0, 320, 60); The footerview you just created as the Tablefooterview of TableView is designed to prevent users from accidentally clicking the Exit button when they click the bottom dockitem, so to set up an extra space,            Add the 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 tableview as a tablefooterview, the button is added to the footerview inside, here the button frame x Y 5 is relative to footerview btnexit.frame = Cgre    Ctmake (10, 5, 300, 40);    button on the font size BtnExit.titleLabel.font = [Uifont systemfontofsize:17];        Button's Listener click event [Btnexit addtarget:self Action: @selector (Exitbtnclick) forcontrolevents:uicontroleventtouchupinside];    Classification method, set button Normal and highlight when background picture (can stretch) [Btnexit setbtnbgimgfornormalandhighightedwithname:@ "Common_button_red.png"];    Set the text on the button, the last group, the array has only one row, each line is a dictionary nsstring *btntitle = [_groups lastobject][0][@ "name"];                [Btnexit Settitle:btntitle Forstate:uicontrolstatenormal]; 3, the most important step is to add the exit button you just created to the TablevieW of Tablefooterview//[footerview Addsubview:btnexit]; [Self.tableView.tableFooterView addsubview:btnexit];} Response Click Set Click event-(void) settings{log (@ "Click the Settings button");}    Click the Exit button-(void) exitbtnclick{//Cancelbuttontitle black//Destructivebuttontitle red//otherbuttontitles greyish white Uiactionsheet *actionsheet = [[Uiactionsheet alloc] initwithtitle:@ "OK to exit this account?"        "Delegate:nil cancelbuttontitle:@" Cancel "destructivebuttontitle:@" Red "otherbuttontitles:@" other ", nil]; Uiactionsheet is best shown on the window, so it is not afraid of the 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 Didselectrowatindexpath: (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 loop use-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{ return _groups.count-1;} Number of rows per group-(Nsinteger) TableView: (UITableView *) TableView numbErofrowsinsection: (Nsinteger) section{//Gets an array consisting of each row nsarray *rows = _groups[section]; Returns the number of rows for the group return rows.count; Each row of each group displays unique content-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *)    indexpath{static NSString *cellid = @ "Beyond";    1. Obtain the cell UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellid] in the pool first; If empty, create a new if (cell = = nil) {//Create a new cell cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcel        Lstyledefault Reuseidentifier:cellid];        1.1. Clear the background of the text label cell.textLabel.backgroundColor = [Uicolor Clearcolor];                1.2. Set text label highlighting text color is also the default text color (do not let it color) Cell.textLabel.highlightedTextColor = Cell.textLabel.textColor;        1.3. Focus, when created, initializes the background view of the cell and the background view when selected Uiimageview *bgimgview = [[Uiimageview alloc] init];                Cell.backgroundview = Bgimgview;        Uiimageview *selectedbgimgview = [[Uiimageview alloc] init]; CelL.selectedbackgroundview = Selectedbgimgview; }//2. Set the cell's unique content//set the caption text to be displayed in groups----and the first few lines---> Dictionary cell.textLabel.text = _groups[indexpath.section][indexp        ath.row][@ "Name"];    3. Set the cell background image//first remove the cell background view Uiimageview *bgimgview = (Uiimageview *) Cell.backgroundview;        Uiimageview *selectedbgimgview = (Uiimageview *) Cell.selectedbackgroundview;    Sub-conditions the background image of the cell file name//In this group, the array consisting of each row nsarray *rows = _groups[indexpath.section];    Get the group, the total number of int rowNum = Rows.Count;        NSString *name = nil;    if (RowNum = = 1) {//If there is only one row in the group, use a picture with the corners full half-width name = @ "Common_card_background.png"; } else if (Indexpath.row = = 0) {//If there is not more than one row for the group and the current row is the first row of the group, use the top half rounded picture name = @ "Common_card_top_background.pn    G "; } else if (Indexpath.row = = rowNum-1) {//If there is not more than one row for the group and the current row is the last row of the group, use the bottom half rounded picture name = @ "Common_card_bottom_    Background.png "; } else {//middle//If there are not more than one row in the group, and the current row is not the first row of the group and not the last row of the group, use a picture with no rounded corners for four weeks 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, sub-text and picture two case discussion if (indexpath.section = = 2) {///If it is group 2nd, the text is displayed, "Reading Mode-subject" UILabel *label =        [[UILabel alloc] init];        Clear 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 right label.textalignment = Nstextalignmentright;        The width height of the label frame label.bounds = CGRectMake (0, 0, 100, 30); The 1th line of the group shows "graph mode" and line 2nd shows "Classic theme" Label.text = (Indexpath.row = = 0)?        @ "graphic mode": @ "Classic theme";    Finally, the custom rightmost view is set to the cell's attached view cell.accessoryview = label; } else {//If it is a different group, display the right picture arrow Cell.accessoryview = [[UIImageView alloc] initwithimage:[uiimage imagenamed:@ "Common_icon_arrow.png"]; }//5. Return to cell return cell;} @end


Data source for "more" pages more.plist










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.