Simple use of Ios_12_tableviewcell

Source: Internet
Author: User

Final:



Girl.h

  girl.h//  11_tableview Use _ Red Mansions////  Created by Beyond on 14-7-26.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <Foundation/Foundation.h> @interface girl:nsobject//UI controls with a weak, string with copy, Other objects with strong//avatar picture name @property (nonatomic,copy) nsstring *headimgname;//name @property (nonatomic,copy) NSString *name;// Verdict @property (nonatomic,copy) NSString *verdict;//provides a class method, which is a constructor that returns the object that encapsulates the data (return ID also) + (Girl *) girlnamed: (NSString *) Name Headimgname: (nsstring*) Headimgname verdict: (NSString *) verdict; @end



girl.m

  girl.m//  11_tableview Use _ Red Mansions////  Created by Beyond on 14-7-26.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import "Girl.h" @implementation girl//provides a class method, which is a constructor that returns the object that encapsulates the data (return ID also) + (Girl *) girlnamed: ( NSString *) name Headimgname: (NSString *) Headimgname Verdict: (NSString *) verdict{    Girl *girl = [[Girl alloc]init];< C7/>girl.name = name;    Girl.headimgname = Headimgname;    girl.verdict = verdict;    return girl;} @end



BeyondViewController.h

  beyondviewcontroller.h//  11_tableview Use _ Red Mansions////  Created by Beyond on 14-7-26.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface beyondviewcontroller:uiviewcontroller// Refresh the table with @property (weak, nonatomic) Iboutlet UITableView *tableview; @end


Beyondviewcontroller.m

beyondviewcontroller.m//11_tableview Use _ Red Mansions////Created by Beyond on 14-7-26.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h" #import "Girl.h" @interface Beyondviewcontroller () < uitableviewdatasource,uitableviewdelegate,uialertviewdelegate>{//Storing false data Nsmutablearray *_array;}    @end @implementation beyondviewcontroller-(void) viewdidload{[Super Viewdidload]; _array = [Nsmutablearray array];//false data [_array addobject:[girl girlnamed:@ "Lin Daiyu" headimgname:@ "0.png" verdict:@ "Alas shutdown de, mercy Yong Xu. Jade Belt in the forest hanging, gold hairpin snow buried.        "]]; [_array addobject:[girl girlnamed:@ "Xue Bao-Chai" headimgname:@ "1.png" verdict:@ "regrettable downtime, the mercy of Xu Xu." Jade Belt in the forest hanging, gold hairpin snow buried.        "]]; [_array addobject:[girl girlnamed:@ "Miaoyu" headimgname:@ "2.png" verdict:@ "to clean ever clean, cloud empty may not be empty." Poor treasures, the end of the mud.        "]]; [_array addobject:[girl girlnamed:@ "Shi Xiangyun" headimgname:@ "3.png" verdict:@ "What is Wealth?" Between the swaddling parents. Dispossessed hanging oblique Fai, Xiang River died Zhuyunfei.        "]]; [_array addobject:[girl girlnamed:@ "Spring" headimgname:@ "4.png" verdict:@ "to self-Qing Mingzhi from high, born in the end of the end of the movement. Qingming Tiqi Jiang Wang, thousands of miles east windA dream away.        "]]; [_array addobject:[girl girlnamed:@ "Cherish the Spring" headimgname:@ "5.png" verdict:@ "is not often broken three springs, called Witton change Xinian makeup. Poor show-house hou Door girl, alone lying beside the long praying.        "]]; [_array addobject:[girl girlnamed:@ "Wang Xifeng" headimgname:@ "6.png" verdict:@ "every bird from the end of the end, all know love this life." A from two make three people wood, cry to jinling thing can mourn.    "]]; } #pragma mark-tableview Data source method//Data source method, special case, important ~ How many groupings (default is return 1)-(Nsinteger) Numberofsectionsintableview: ( UITableView *) tableview{//single Group of data display, do not need to group, so return 1, (the default is to return 1) return 1;} Data source methods, each group, how many rows-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{return 7;} The data source method, each row of each group should show how the interface (including the encapsulated data), the focus!!! Every time a row of cells enters the field of view will be called//must be implemented otherwise, terminating app due to uncaught exception ' nsinternalinconsistencyexception ', Reason: ' U Itableview DataSource must return a cell from Tableview:cellforrowatindexpath: '-(UITableViewCell *) TableView: (    UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static NSString *cellid = @ "Beyond"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:ceLlid];   if (cell = = nil) {//If not in the pool, regenerate one cell/* Cell 4 styles: 1,default left-hand text 2,subtitle Left the text large under the text small 3,value 1 left picture left text large right text small 3,value 2 disgusting left text small right text large */cell = [[UI    Tableviewcell Alloc]initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:cellid];        }//Set unique content in cell Girl *girl = _array[indexpath.row];    Cell.imageView.image = [UIImage imageNamed:girl.headImgName];    Cell.textLabel.text = Girl.name;    Cell.detailTextLabel.text = girl.verdict;    Set the right side of the cell//Cell.accessorytype = Uitableviewcellaccessorydetailbutton;    Cell.accessorytype = Uitableviewcellaccessorydetaildisclosurebutton;    Cell.accessorytype = Uitableviewcellaccessorydisclosureindicator; returns cell return cell; #pragma Mark-tableview Proxy method//proxy method, each line how high-(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: ( Nsindexpath *) indexpath{return 93;} Proxy method, which will be called when a line is clicked-(Nsindexpath *) TableView: (UITableView *) TableView Willselectrowatindexpath: (Nsindexpath *) indexpath{NSLog (@ "would select----%d",            Indexpath.row); return Indexpath;} Proxy method, called when a row is clicked-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{NSLog (@    "Did select----%d", indexpath.row);    [TableView Deselectrowatindexpath:indexpath Animated:yes];    Girl *girl = _array[indexpath.row]; Pop-up name for user to change//set Agent to respond to alert button click event//uialertview *alert = [[Uialertview alloc] InitWithTitle:girl.name message    : Girl.verdict delgate:self cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "other", nil];    Uialertview *alert = [[Uialertview alloc]init]; [Alert initWithTitle:girl.name message:girl.verdict delegate:self cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "OK",    NIL];    Alertviewstyle style----Password//Alert.alertviewstyle = Uialertviewstylesecuretextinput;    Alertviewstyle style----general text input Box Alert.alertviewstyle = Uialertviewstyleplaintextinput; AlErtviewstyle style----username and password login box//Alert.alertviewstyle = Uialertviewstyleloginandpasswordinput;        Alertviewstyle style----Label Display//Alert.alertviewstyle = Uialertviewstyledefault;    Username password in case there are two text boxes Uitextfield *textfield = [alert textfieldatindex:0];    Textfield.text = Girl.name;    The key code, through the tag will click the line number to the Alertview proxy method, but also by taking advantage of the agent is the controller member carries on the line number the transmission ~ Textfield.tag = Indexpath.row;    Show Alertview [Alert show]; /* By default, the above alert is a local variable, and will be released when this method is finished, however, the [Alert show] method will have a mechanism (such as UIWindow will hold its reference so that it is not destroyed) */}//proxy method, when canceling the click of a row When called-(void) TableView: (UITableView *) TableView Diddeselectrowatindexpath: (Nsindexpath *) indexpath{NSLog (@ "did Deselect row----%d ", indexpath.row);} Proxy method for #pragma mark-uialertviewdelegate-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger)    buttonindex{//View click on which button in Alertview, the Cancel button is 0 NSLog (@ "Alertview button inside the index---%d", buttonindex);    if (Buttonindex = = 0) {//0 represents the Cancel button return; }else if (buttoniNdex = = 1) {//1 means OK button, update data source, reload data Uitextfield *textfield = [Alertview textfieldatindex:0];        NSString *newname = [TextField text];        Robust judgment if ([NewName isequaltostring:@ ""]) {return;        }//First update data source int row = Textfield.tag;        Girl *girl = _array[row];        Girl.name = NewName;                Again, all reload data//[_tableview reloaddata];        Preferably, the local refresh data, through the row to generate a indexpath array nsindexpath *indexpath = [Nsindexpath indexpathforrow:row insection:0];        Nsarray *indexpaths = @[indexpath];    [_tableview reloadrowsatindexpaths:indexpaths Withrowanimation:uitableviewrowanimationleft]; }} @end



Tableviewcellaccessory





Tableviewcellstyle






TableView Data source












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.