IOS-intermediate, ios

Source: Internet
Author: User

IOS-intermediate, ios

// Set the Row Height of tableView
Self. tableView. rowHeight = 100;
// Set the tableView split line style
// UITableViewCellSeparatorStyleNone does not display the split line
// Trim display split line (default) self. tableView. separatorStyle = UITableViewCellSeparatorStyleSingleLine; self. tableView. allowsSelection = NO; // do not allow selection // set the color of the split line
Self. tableView. separatorColor = [UIColor orangeColor]; // do not display the [tips] self. tableView. tableFooterView = [[UIView alloc] init]; // set (top, left, bottom, right) [top and bottom are invalid] self. tableView. separatorInset = UIEdgeInsetsMake (0, 10, 0, 10 );
Load cell CZFriendCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "friend"]; return cell in stroyborud;


Common dataSource methods/*** how many groups numberOfSectionsInTableView */
-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 2;
}

/*** Number of rows in a group numberOfRowsInSection */
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section
{Return 2 ;}

/*** What is displayed in each group? cellForRowAtIndexPath */
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {// 1 create Cellstatic NSString * reusedId = @ "item ";
// UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: reusedId forIndexPath: indexPath]; ---------> wrong !!!!!
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: reusedId];

If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: reusedId];} // 2. obtain data LYGroup * group = _ groups [indexPath. section];
LYItem * item = group. items [indexPath. row];
Cell. textLabel. text = item. title; cell. imageView. image = [UIImage imageNamed: item. icon]; // 3. return cell ;}
/*** Group (header) Title titleForHeaderInSection */
-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {return @ "Header ";}

/*** Group (tail) Description titleForFooterInSection */
-(NSString *) tableView :( UITableView *) tableView titleForFooterInSection :( NSInteger) section
{Return @ "tail";}/*** grouping index sectionIndexTitlesForTableView */
-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView
{
// Return the title attribute of all group objects in the group array. The returned value is an array.
Return [self. carGroups valueForKeyPath: @ "title"];}
Common proxy method # pragma mark-proxy method
/*** Set the Row Height of each row. heightForRowAtIndexPath */
-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath
{
If (indexPath. row % 2 = 0 ){
Return 60;
} Else {
Return 100;
}
}
/*** Select a row of didSelectRowAtIndexPath */
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath
{
// Zd long, long, int
NSLog (@ "the user selected the % zd group, row % zd", indexPath. section, indexPath. row );
}

// When a row is deselected, execute didDeselectRowAtIndexPath-(void) tableView :( UITableView *) tableView didDeselectRowAtIndexPath :( NSIndexPath *) indexPath
{
NSLog (@ "the user unselects the % zd group, row % zd", indexPath. section, indexPath. row );}
CELL common attributes // UITableViewCell * cell = [[UITableViewCell alloc] init]; // UITableViewCellStyleDefault only displays icons and names
// UITableViewCellStyleSubtitle display icon, name, description <below>
// UITableViewCellStyleValue1 display icon, name, description <later> // UITableViewCellStyleValue2 display name, description <later> // background View color UIView * backView = [[UIView alloc] init];
BackView. backgroundColor = [UIColor redColor];
// The priority of backgroundView is higher than that of backgroundColor.
Cell. backgroundView = backView;
// Background color
Cell. backgroundColor = [UIColor blueColor];

UIView * selectedView = [[UIView alloc] init];
SelectedView. backgroundColor = [UIColor blueColor];
// Select the background View
Cell. selectedBackgroundView = selectedView;

// Indicator-related
// Set the indicator type
Cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Indicator view cell. accessoryView = [[UISwitch alloc] init];/*** retrieve cell from cache // 1 create Cell // 2. get Data // 3. return cell * // define the reuse ID
Static NSString * reuseId = @ "heroCell ";

// Find the reused cell in the buffer pool
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: reuseId];
// Create a new cell if no cell is found.
If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: reuseId];
// NSLog (@ "create cell ");}
// Used to refresh the specified row [self. tableView reloadRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationNone]; // refresh the table [self. tableView reloadData];
// Scroll to make a region visible [self. tableView scrollRectToVisible: (CGRect) rect animated: YES];
// Specifies the row to which NSIndexPath * indexPath = [NSIndexPath indexPathForRow: self. tgs. count-1 inSection: 0]; [self. tableView scrollToRowAtIndexPath: indexPath atScrollPosition :( UITableViewScrollPositionMiddle) animated: YES]; // headerView self. tableView. tableHeaderView = [[UIView alloc] initWithFrame: CGRectMake (0, 0, 0, 15)]; // set the group spacing to 15 self. tableView. sectionHeaderHeight = 15;
Self. tableView. sectionFooterHeight = 0;

// Set the background image of tableView
Self. tableView. backgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "bg"]; // rewrite the init method and set the group

  • -(Instancetype) init {
Return [super initWithStyle: UITableViewStyleGrouped]; rewrite [[self alloc] Using: reuseId]; UITableViewCell rewrite [[self alloc] initWithStyle :( UITableViewCellStyleDefault) reuseIdentifier: ID]

Related Article

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.