UITableView and uitableview
Style // common UITableViewStylePlain, // group UITableViewStyleGrouped // table view UITableView * tableView = [[UITableView alloc] initWithFrame: self. view. bounds style: UITableViewStylePlain]; // sets the data source tableView. dataSource = self; // sets the proxy tableView. delegate = self; // The height of the partition header tableView. sectionHeaderHeight = 30; // The height at the end of the partition tableView. sectionFooterHeight = 30; // The Row Height. The default Row Height is 44. // TableView. rowHeight = 100; // tableView. backgroundColor = [UIColor grayColor];/* UITableViewCellSeparatorStyleNone has no UITableViewCellSeparatorStyleSingleLine single-line timeline. separatorStyle = UITableViewCellSeparatorStyleSingleLine; // _ tableView. separatorColor = [UIColor redColor]; // the padding of the line _ tableView. separatorInset = UIEdgeInsetsMake (0, 0, 0, 0); // use _ tableView when the row height is fixed. rowHeight = 60; // set the background View // UIImageView * imageView = [[UIImageView alloc] initWithFrame: tableView. bounds]; // imageView. image = [UIImage imageNamed: @ "baby.jpg"]; // tableView. backgroundView = imageView; // the background of the index area _ tableView. sectionIndexBackgroundColor = [UIColor whiteColor]; // set the color of the index text _ tableView. sectionIndexColor = [UIColor blueColor]; // if the number of cells is smaller than the number of rows, the index _ tableView is displayed. se CtionIndexMinimumDisplayRowCount = 100; // select the background color when indexing _ tableView. sectionIndexTrackingBackgroundColor = [UIColor clearColor]; // sets the editing mode [self. tableView setEditing: YES animated: YES]; // obtain all the selected rows NSArray * deleteList = [self. tableView indexPathsForSelectedRows]; proxy UITableViewDataSource, UITableViewDelegate // Several sections-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return self. peopleLis T. count;} // The number of Rows in a Rows group. By default, only one Section exists. the index of the group is 0-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {NSArray * p = self. peopleList [section]; return p. count;} // cell, IndexPath index // UITableViewCell is the cell that makes up UITableView-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [[UITableV IewCell alloc] init]; cell. textLabel. text = self. peopleList [indexPath. section] [indexPath. row]; // clearColor is a transparent cell. backgroundColor = [UIColor clearColor]; return cell;} // return the title at the top of the partition-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {return self. headList [section];} // return the title at the end of the partition-(NSString *) tableView :( UITableView *) tableView titleForFooterInSection :( NSInteger) Section {return self. footList [section];} // select a row-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {// deselect a row [tableView deselectRowAtIndexPath: indexPath animated: YES]; // go to the next NSString * vcName = self. viewControllers [indexPath. section] [indexPath. row]; UIViewController * vc = [[NSClassFromString (vcName) alloc] init]; [self. navigationController pushViewContr Oller: vc animated: YES];} // color between section gaps-(UIView *) tableView :( UITableView *) tableView viewForHeaderInSection :( NSInteger) section {UIView * v = [[UIView alloc] init]; v. backgroundColor = [UIColor greenColor]; return v;} // This proxy method always calls-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) When scrolling the table *) indexPath {// reuse mechanism of UITableViewCell static NSString * identifier = @" CellID "; // find the corresponding cell UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: identifier] From the reuse pool; if (! Cell) {/* UITableViewCellStyleDefault: displays the secondary image. UITableViewCellStyleValue1: displays the secondary image, common text, and description text. UITableViewCellStyleValue2 does not display the image, displays secondary images, common text, and description text. A total of UITableViewCellStyleSubtitle displays secondary images, common texts, and description texts, two rows in total */cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: @ "cellID"];} Industry * industry = self. dataList [indexPath. row]; cell. textLabel. text = industry. name; cell. detailTextLabel. text = industry. state; cell. imageView. image = [UIImage imageNamed: industry. icon]; cell. accessoryType = UITableViewCellAccessoryDetailButton; return cell;} // sets the Row Height method. If this proxy method is implemented, rowHeight is invalid. This is mainly used to set the variable cell height //-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {// return 100; //} // index display question-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {return [self. dataList valueForKey: @ "title"];} // returns whether the table view can be edited-(BOOL) tableView :( UITableView *) tableView canEditRowAtIndexPath :( NSIndexPath *) indexPath {return YES ;} // returns whether the table view can be rolled-(BOOL) tableView :( UITableView *) tableView canMoveRowAtIndexPath :( NSIndexPath *) indexPath {return YES ;} // confirm the edited option/* UITableViewCellEditingStyle ← do not edit ← Delete ← insert */-(void) tableView :( UITableView *) tableView commitEditingStyle :( comment) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath {// if it is a delete operation if (editingStyle = UITableViewCellEditingStyleDelete) {// delete data from the data source [self. dataList removeObjectAtIndex: indexPath. row]; // Delete the element NSArray * deleteIndexs = @ [indexPath] According to the indexPath array; // UITableViewRowAnimation operation animation [tableView metadata: deleteIndexs withRowAnimation: animation];}-(void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath {if (editingStyle = UITableViewCellEditingStyleDelete) {[self. dataList removeObjectAtIndex: indexPath. row]; // refresh the table // [tableView reloadData]; // refresh the delete operation [tableView deleteRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationFade];} else if (editingStyle = UITableViewCellEditingStyleInsert) {// insert operation [self. dataList insertObject: @ "baby" atIndex: indexPath. row]; [tableView insertRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationFade];} // The method to be implemented by moving the object // sourceIndexPath start position // destinationIndexPath target location-(void) tableView :( UITableView *) tableView moveRowAtIndexPath :( NSIndexPath *) sourceIndexPath toIndexPath :( NSIndexPath *) destinationIndexPath {NSString * name = self. dataList [sourceIndexPath. row]; [self. dataList removeObjectAtIndex: sourceIndexPath. row]; [self. dataList insertObject: name atIndex: destinationIndexPath. row];} // modify the delete button-(NSString *) tableView :( UITableView *) tableView titleForDeleteConfirmationButtonForRowAtIndexPath :( NSIndexPath *) indexPath {return @ "are you sure you want to delete ";} // by default, tableView (UITableView *) tableView editingStyleForRowAtIndexPath :( NSIndexPath *) indexPath {// return metadata;}-(UITableViewCellEditingStyle) tableView :( UITableView *) tableView editingStyleForRowAtIndexPath :( NSIndexPath *) indexPath {// return UITableViewCellEditingStyleInsert | UITableViewCellEditingStyleDelete ;}