UITableView, androiduitableview
</Pre> <pre name = "code" class = "objc">-(void) loadView {/*** UITableView: Table view, it is a powerful control used in iOS to display and edit a series of information lists with the same data structure. (VIP ). UITableView inherits from UIScrollView, so it can slide, but it can only slide vertically, and there is only one column. UITableView is a partition (section, corresponding to the group of class students) and a row (row, corresponding to the group members ). the index values for partitions and rows start from 0. if you want to obtain a row (obtain a person in the class ), it depends on the partition and the row of the partition (based on the group of the student and the location of the student in the group (the number of persons. both information is stored in NSIndexPath objects. each row of UITableView is a UITableViewCell object. Each cell contains an imageView (lef T), label (textLabel, detailLabel, center), accessoryView (right) */UITableView * tableView = [[UITableView alloc] initWithFrame: [UIScreen mainScreen]. bounds style: UITableViewStylePlain]; // sets the style of the split line. // tableView. separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched; // set the color of the split line to tableView. separatorColor = [UIColor lightGrayColor]; // specify the tableView data source. (provides data support for tableView display ). subject to the UITableViewDataSource Protocol TableView. dataSource = self; // sets the tableView proxy (used to handle cell click events ). tableView. delegate = self; // set the tableView Row Height to tableView. rowHeight = 70; self. view = tableView; [tableView release];}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. navigationItem. title = @ "9 class" ;}# pragma mark-UITableViewDataSource // you can specify the number of rows in tableView (the number of rows in each group)-(NSInteger) tableView :( UITableVie W *) tableView numberOfRowsInSection :( NSInteger) section {// 1. obtain the key value // NSString * key = self. titles [section]; // 2. obtain the corresponding array based on the key value // NSArray * group = self. names [key]; // 3. evaluate the number of array elements // return [group count]; // return [self. names [self. titles [section] count]; return 1000;} // used to create a cell. Each row corresponds to a cell. -(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {// 1. Create a reuse identifier static NSString * identifier = @ "7ban"; // 2. reuse the cell in the queue based on the reuse identifier. studentCell * cell = [tableView dequeueReusableCellWithIdentifier: identifier]; // 3. determine whether reusable cells are successfully obtained. if (! Cell) {// If the reusable cell is not obtained successfully, create a cell. // after creating a cell, you must add a reuse identifier to the cell. it facilitates reuse by others. cell = [[[StudentCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: identifier] autorelease];} cell. textLabel. text = @ "Bean"; cell. detailTextLabel. text = @ "pandatv"; return cell; // 1. first obtain key // NSString * key = self. titles [indexPath. section]; // 2. obtain value (array) based on the key // NSArray * group = self. names [key]; // 3. extract the element // NSString * name = group [indexPath. row]; // cell. textLabel. text = [[self. names objectForKey: [self. titles objectAtIndex: indexPath. section] objectAtIndex: indexPath. row];} // returns the number of tableView partitions //-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView // {// return [self. names count]; // you can specify the text displayed in each partition header. (header) //-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section // {// return self. titles [section]; // you can specify the index value on the Right of tableView to quickly locate the partition ), to match the title of each partition //-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView // {// return self. titles; // # pragma mark-UITableViewDelegate // sets the Row Height-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {// The even cell height is 100, and the odd cell height is 50 if (indexPath. row % 2) {return 100;} return 50;} // triggered when the cell is selected-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {NSLog (@ "% d", indexPath. row );}
How does UITableView hide a section?
Solved. First, tableView. sectionHeaderHeight = 0; tableView. sectionFooterHeight = 0; then implement:-(CGFloat) tableView :( UITableView *) tableView preview :( NSInteger) section-(CGFloat) tableView :( UITableView *) tableView heightForFooterInSection :( NSInteger) section to control the hidden section in group mode.
How does uitableview obtain the specified split line and set the color?
The separator of UITableView is a private class and cannot be obtained.
However, you can modify the table view attributes:
UITableView * tableView = [[UITableView alloc] initWithFrame: CGRectMake (20, 20,400,300) style: UITableViewStylePlain]; tableView. separatorColor = [UIColor redColor]; tableView. separatorInset = UIEdgeInsetsMake (, 0, 80); // set the end distance, which indicates that the separator is 80 pixels away from the left and right tableView. separatorStyle = UITableViewCellSeparatorStyleSingleLine; tableView. dataSource = self;
TableView after this setting is as follows: (80 pixels are left and right)
If you want to set the color of a single split line, draw the split line by yourself. You can use coreGraphics or UIView to draw images:
UITableView * tableView = [[UITableView alloc] initWithFrame: CGRectMake (20, 20,400,300) style: UITableViewStylePlain]; tableView. separatorStyle = UITableViewCellSeparatorStyleNone; // This will not display the built-in split line tableView. dataSource = self; for (int I = 0; I <8; I ++) {UIView * separator = [[UIView alloc] initWithFrame: CGRectMake (10, (I + 1) * 40/* I x height */, 380, 1)]; separator. backgroundColor = [UIColor colorWithRed: 0.03 * I green: 0.05 * I blue: 0.1 * I alpha: 1]; [tableView addSubview: separator];} [self addSubview: tableView]; effect:
Normal scrolling
Of course, in order to be harmonious, you should set the custom separator interval to be consistent with the cell height.