Simple use of iOS_12_tableViewCell

Source: Internet
Author: User

Simple use of iOS_12_tableViewCell
Finally:



Girl. h

/// Girl. h // 11_tableView usage _ Dream of Red Mansions /// Created by beyond on 14-7-26. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
 
  
@ Interface Girl: NSObject // weak is used for the UI control, copy is used for the string, and strong // is used for other objects. The picture name @ property (nonatomic, copy) NSString * headImgName is used; // name @ property (nonatomic, copy) NSString * name; // discriminant @ property (nonatomic, copy) NSString * verdict; // provides a class method, that is, constructor, returns the encapsulated Data Object (or the returned id) + (Girl *) girlNamed :( NSString *) name headImgName :( NSString *) headImgName verdict :( NSString *) verdict; @ end
 



Girl. m

/// Girl. m // 11_tableView usage _ Dream of 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, that is, the constructor, which returns the encapsulated Data Object (the returned id can also be) + (Girl *) girlNamed :( NSString *) name headImgName :( NSString *) headImgName verdict :( NSString *) verdict {Girl * girl = [[Girl alloc] init]; girl. name = name; girl. headImgName = headImgName; girl. verdict = verdict; return girl;} @ end



BeyondViewController. h

//// BeyondViewController. h // 11_tableView usage _ Dream of Red Mansions /// Created by beyond on 14-7-26. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
 
  
@ Interface BeyondViewController: UIViewController // @ property (weak, nonatomic) IBOutlet UITableView * tableView is used to refresh the table; @ end
 


BeyondViewController. m

//// BeyondViewController. m // 11_tableView usage _ Dream of 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 ()
 
  
{// Save holiday 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: @" can sigh the power of shutdown, it is easy to pity. The jade belt hangs in the forest and is buried in the snow. "]; [_ Array addObject: [Girl girlNamed: @" Xue Baochai "headImgName: @" 1.png" verdict: @ "you can sigh about the shutdown mode. The jade belt hangs in the forest and is buried in the snow. "]; [_ Array addObject: [Girl girlNamed: @" "headImgName: @" 2.png" verdict: @ ", cloud blank may not be empty. Poor gold and Jade, eventually trapped in the mud. "]; [_ Array addObject: [Girl girlNamed: @" Shi Xiangyun "headImgName: @" 3.png" verdict: @ "What is rich? Parental violations during the peak hours. The eye is shining brightly, And the Xiangjiang River passes. "]; [_ Array addObject: [Girl girlNamed: @" Chun "headImgName: @" 4.png" verdict: @ "is self-explanatory, born at the end of the world. The pure brightness of the Weeping River side, a thousand miles of Dongfeng dream. "]; [_ Array addObject: [Girl girlNamed: @" Hunchun "headImgName: @" 5.png" verdict: @ "it is not uncommon for sunspring scenes, and yiyundun has changed its makeup. Poor show households Hou men female, lie alone beside the ancient Buddha. "]; [_ Array addObject: [Girl girlNamed: @" Wang Xifeng "headImgName: @" 6.png" verdict: @ "from the end of the age, I know that I love my life. From the second to the third man, crying to Jinling can be sad. "] ;}# Pragma mark-tableView data source method // data source method, special case, important ~ Total number of groups (1 is returned by default)-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {// display of single group of data. Therefore, 1 is returned, (1 is returned by default) return 1;} // data source method, the number of rows in each group-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return 7;} // data source method. The interface (including encapsulated data) of each row in each group should be displayed !!! // Call whenever a cell enters the field of view. // required. Otherwise, Terminating app due to uncaught exception 'nsinternalinconsistencyexception', reason: 'uitableview dataSource must return a cell from tableView: cellForRowAtIndexPath: '-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * cellID = @ "Beyond"; UITableViewCell * cell = [tableView details Entifier: cellID]; if (cell = nil) {// if the pool is not obtained, generate a new four cell/* cell styles: 1, default: 2 for the left text, 3 for the left text of the subtitle, 3 for the left text, 3 for the left text, 3 for the right text, value 2 nausea left text small right text large */cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: cellID];} // set the unique content 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 affiliated unit // cell. accessoryType = UITableViewCellAccessoryDetailButton; // cell. accessoryType = UITableViewCellAccessoryDetailDisclosureButton; cell. accessoryType = response; // return cell;} # proxy method of pragma mark-tableView. // The height of each row-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPa Th :( NSIndexPath *) indexPath {return 93;} // proxy method. Call-(NSIndexPath *) tableView :( UITableView *) tableView willSelectRowAtIndexPath :( NSIndexPath *) when you want to click a row *) indexPath {NSLog (@ "will select ---- % d", indexPath. row); return indexPath;} // proxy method. When you click a row, call-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {NSLog (@ "did select ---- % d", indexPath. row); [tableView deselectRowAt IndexPath: indexPath animated: YES]; Girl * girl = _ array [indexPath. row]; // The name is displayed for the user to change // The proxy is set in response to the 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 cancelButt OnTitle: @ "cancel" otherButtonTitles: @ "OK", nil]; // alertViewStyle ---- password // alert. alertViewStyle = UIAlertViewStyleSecureTextInput; // alertViewStyle ---- general text input box alert. alertViewStyle = UIAlertViewStylePlainTextInput; // alertViewStyle ---- user name and password logon box // alert. alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; // alertViewStyle ---- Label display // alert. alertViewStyle = UIAlertViewStyleDefault ;// The username and password contain two text boxes: UITextField * textField = [alert textFieldAtIndex: 0]; textField. text = girl. name; // key code. A tag is used to bring the clicked row number to the proxy method of alertView. You can also use the proxy, that is, the Controller member, to transfer the row number ~ TextField. tag = indexPath. row; // display alertView [alert show];/* by default, the above alert is a local variable. After this method is completed, it will be released, [alert show] method, there will be a mechanism (for example, UIWindow will hold its reference so that it will not be destroyed) * // proxy method, call-(void) tableView :( UITableView *) tableView didDeselectRowAtIndexPath :( NSIndexPath *) indexPath {NSLog (@ "did deselect row ---- % d", indexPath. row) ;}# pragma mark-delegate proxy method-(void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {// view which button in alertView is clicked, the cancel button is 0 NSLog (@ "index --- % d", buttonIndex) in alertView; if (buttonIndex = 0) {// 0 indicates the cancel button return ;} else if (buttonIndex = 1) {// 1 indicates the OK button, update the data source, and reload the data UITextField * textField = [alertView textFieldAtIndex: 0]; NSString * newName = [textField text]; // robust determines if ([newName is1_tostring: @ ""]) {return ;}// first update the data source int row = textField. tag; Girl * girl = _ array [row]; girl. name = newName; // re-load all data // [_ tableView reloadData]; // preferably, partial data refresh, use row to generate an indexPath array NSIndexPath * indexPath = [NSIndexPath indexPathForRow: row inSection: 0]; NSArray * indexPaths = @ [indexPath]; [_ tableView reloadRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationLeft]; }}@ end
 



TableViewCellAccessory





<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + dgfiber gvwawv3q2vsbfn0ewxlpgjypgo8l3a + CjxwPjxicj4KPC9wPgo8cD48aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20140728/2014072809125187.png" alt = "\">




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.