Basic implementation
I. Project structure and plist documents
Second, the implementation of the Code
1. Description:
Host controller inherits Uitableviewcontroller directly
Copy Code code as follows:
YYViewController.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Yyviewcontroller:uitableviewcontroller
@end
Associated with the storyboard
2. Code
Data Model section:
YYQQGroupModel.h file
Copy Code code as follows:
//
YYQQGroupModel.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Yyqqgroupmodel:nsobject
/**
* Name attribute
*/
@property (nonatomic,copy) NSString *name;
/**
* Is online
*/
@property (nonatomic,copy) NSString *online;
/**
* Friends List
*/
@property (Nonatomic,strong) Nsarray *friends;
-(Instancetype) Initwithdict: (Nsdictionary *) dict;
+ (Instancetype) qqgroupmodelwithdict: (Nsdictionary *) dict;
@end
YYQQGROUPMODEL.M file
Copy Code code as follows:
//
yyqqgroupmodel.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYQQGroupModel.h"
#import "YYFriendsModel.h"
@implementation Yyqqgroupmodel
-(Instancetype) Initwithdict: (Nsdictionary *) dict
{
if (Self=[super init]) {
Convert a dictionary to a model
[Self setvaluesforkeyswithdictionary:dict];
Defines an array to hold the converted Model
Nsmutablearray *models=[nsmutablearray ArrayWithCapacity:self.friends.count];
For (Nsdictionary *dict in self.friends) {
Yyfriendsmodel *friends=[yyfriendsmodel Friendswithdict:dict];
[Models Addobject:friends];
}
_friends=[models copy];
}
return self;
}
+ (Instancetype) qqgroupmodelwithdict: (Nsdictionary *) dict
{
return [[Self alloc]initwithdict:dict];
}
@end
YYFriendsModel.h file
Copy Code code as follows:
//
YYFriendsModel.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Yyfriendsmodel:nsobject
/**
* Name of each friend
*/
@property (nonatomic,copy) NSString *name;
/**
* The head of every friend
*/
@property (nonatomic,copy) NSString *icon;
/**
* Individual signature of each friend
*/
@property (nonatomic,copy) NSString *intro;
/**
* Whether the friend is a VIP
*/
@property (Nonatomic,assign,getter = ISVIP) BOOL VIP;
-(Instancetype) Initwithdict: (Nsdictionary *) dict;
+ (Instancetype) friendswithdict: (Nsdictionary *) dict;
@end
YYFRIENDSMODEL.M file
Copy Code code as follows:
//
yyfriendsmodel.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYFriendsModel.h"
@implementation Yyfriendsmodel
-(Instancetype) Initwithdict: (Nsdictionary *) dict
{
if (Self=[super init]) {
[Self setvaluesforkeyswithdictionary:dict];
}
return self;
}
+ (Instancetype) friendswithdict: (Nsdictionary *) dict
{
return [[Self alloc]initwithdict:dict];
}
@end
View section
YYfriendCell.h file
Copy Code code as follows:
//
YYfriendCell.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <UIKit/UIKit.h>
@class Yyfriendsmodel;
@interface Yyfriendcell:uitableviewcell
@property (Nonatomic,strong) Yyfriendsmodel *friends;
+ (Instancetype) Cellwithtableview: (UITableView *) TableView;
@end
YYFRIENDCELL.M file
Copy Code code as follows:
//
yyfriendcell.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYfriendCell.h"
#import "YYFriendsModel.h"
Private extension
@interface Yyfriendcell ()
@end
Copy Code code as follows:
@implementation Yyfriendcell
+ (Yyfriendcell *) Cellwithtableview: (UITableView *) TableView
{
static NSString * identifier=@ "QQ";
Yyfriendcell *cell=[tableview Dequeuereusablecellwithidentifier:identifier];
if (cell==nil) {
//Use the system's own style
Cell=[[yyfriendcell Alloc]initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:identifier];
NSLog (@ "Create a Cell");
}
return cell;
}
-(void) Setfriends: (Yyfriendsmodel *) Friends
{
_friends=friends;
1. Set Avatar
Self.imageview.image=[uiimage Imagenamed:_friends.icon];
2. Set Nicknames
Self.textlabel.text=_friends.name;
3. Setup Introduction
Self.detailtextlabel.text=_friends.intro;
Judge whether it is a member
/**
* Here is a note, if not write else set to black, what will happen?
*/
if (_FRIENDS.ISVIP) {
[Self.textlabel Settextcolor:[uicolor Redcolor]];
}else
{
[Self.textlabel Settextcolor:[uicolor Blackcolor]];
}
}
@end
Main Controller Section
YYVIEWCONTROLLER.M file
Copy Code code as follows:
//
Yyviewcontroller.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
#import "YYQQGroupModel.h"
#import "YYfriendCell.h"
#import "YYFriendsModel.h"
@interface Yyviewcontroller ()
/**
* Used to hold all grouped data
*/
@property (Nonatomic,strong) Nsarray *groupfriends;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
#pragma mark-lazy Load
1. Get the data first, realize lazy load
-(Nsarray *) groupfriends
{
if (_groupfriends==nil) {
NSString *fullpath=[[nsbundle mainbundle]pathforresource:@ "Friends.plist" oftype:nil];
Nsarray *arraym=[nsarray Arraywithcontentsoffile:fullpath];
Nsmutablearray *models=[nsmutablearray ArrayWithCapacity:arrayM.count];
For (Nsdictionary *dict in Arraym) {
Yyqqgroupmodel *group=[yyqqgroupmodel Qqgroupmodelwithdict:dict];
[Models Addobject:group];
}
_groupfriends=[models copy];
}
return _groupfriends;
}
-(void) viewdidload
{
[Super Viewdidload];
Self.tableView.sectionHeaderHeight = 100;
}
#pragma mark- Set data source
//Return number of groups
//Why isn't there a smart tip? Because these methods are in the UITableView protocol, the default does not comply with the protocol, so that the host controller class inherits Uitableviewcontroller, it has followed the
-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView
{
return self.groupFriends.count;
}
//How many rows are returned per group
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
//Take out the corresponding group model
Yyqqgroupmodel *group=self.groupfriends[section];
//Returns the number of friends in the corresponding group
return Group.friends.count
}
//Each group of contents per line
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
//1. Create cell
Yyfriendcell *cell=[yyfriendcell Cellwithtableview:tableview];
2. Set up cell
Yyqqgroupmodel *group=self.groupfriends[indexpath.section];
Yyfriendsmodel *friends=group.friends[indexpath.row];
Cell.friends=friends;
3. Return a cell
return cell;
}
#pragma mark-Agent method
This method is called when a group header enters the field of view
-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) Section
{
1. Create a Head view
UIView *view = [[UIView alloc] init];
View.backgroundcolor = [Uicolor Graycolor];
2. Return to head view
return view;
}
Set the height of the header for a grouped header
-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section
{
Return 44;
}
#pragma mark hides the status bar
-(BOOL) Prefersstatusbarhidden
{
return YES;
}
@end
The simple effect of achieving:
Third, the attention point
(1) How to set the head view
(2) When overriding the set method, the rollback should be considered.
A more complex implementation
first, the realization effect
Second, the implementation of the Code
1. Data Model Section
YYQQGroupModel.h file
Copy Code code as follows:
//
YYQQGroupModel.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Yyqqgroupmodel:nsobject
/**
* Name attribute
*/
@property (nonatomic,copy) NSString *name;
/**
* Is online
*/
@property (nonatomic,copy) NSString *online;
/**
* Friends List
*/
@property (Nonatomic,strong) Nsarray *friends;
Record whether the current group is to be opened
@property (Nonatomic,assign,getter = isOpen) BOOL open;
-(Instancetype) Initwithdict: (Nsdictionary *) dict;
+ (Instancetype) qqgroupmodelwithdict: (Nsdictionary *) dict;
@end
YYQQGROUPMODEL.M file
Copy Code code as follows:
//
yyqqgroupmodel.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYQQGroupModel.h"
#import "YYFriendsModel.h"
@implementation Yyqqgroupmodel
-(Instancetype) Initwithdict: (Nsdictionary *) dict
{
if (Self=[super init]) {
Convert a dictionary to a model
[Self setvaluesforkeyswithdictionary:dict];
Defines an array to hold the converted Model
Nsmutablearray *models=[nsmutablearray ArrayWithCapacity:self.friends.count];
For (Nsdictionary *dict in self.friends) {
Yyfriendsmodel *friends=[yyfriendsmodel Friendswithdict:dict];
[Models Addobject:friends];
}
_friends=[models copy];
}
return self;
}
+ (Instancetype) qqgroupmodelwithdict: (Nsdictionary *) dict
{
return [[Self alloc]initwithdict:dict];
}
@end
YYFriendsModel.h file
Copy Code code as follows:
//
YYFriendsModel.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Yyfriendsmodel:nsobject
/**
* Name of each friend
*/
@property (nonatomic,copy) NSString *name;
/**
* The head of every friend
*/
@property (nonatomic,copy) NSString *icon;
/**
* Individual signature of each friend
*/
@property (nonatomic,copy) NSString *intro;
/**
* Whether the friend is a VIP
*/
@property (Nonatomic,assign,getter = ISVIP) BOOL VIP;
-(Instancetype) Initwithdict: (Nsdictionary *) dict;
+ (Instancetype) friendswithdict: (Nsdictionary *) dict;
@end
YYFRIENDSMODEL.M file
Copy Code code as follows:
//
yyfriendsmodel.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYFriendsModel.h"
@implementation Yyfriendsmodel
-(Instancetype) Initwithdict: (Nsdictionary *) dict
{
if (Self=[super init]) {
[Self setvaluesforkeyswithdictionary:dict];
}
return self;
}
+ (Instancetype) friendswithdict: (Nsdictionary *) dict
{
return [[Self alloc]initwithdict:dict];
}
@end
2. View section
YYfriendCell.h file
Copy Code code as follows:
//
YYfriendCell.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <UIKit/UIKit.h>
@class Yyfriendsmodel;
@interface Yyfriendcell:uitableviewcell
@property (Nonatomic,strong) Yyfriendsmodel *friends;
+ (Instancetype) Cellwithtableview: (UITableView *) TableView;
@end
YYFRIENDCELL.M file
Copy Code code as follows:
//
yyfriendcell.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYfriendCell.h"
#import "YYFriendsModel.h"
Private extension
@interface Yyfriendcell ()
@end
Copy Code code as follows:
@implementation Yyfriendcell
+ (Yyfriendcell *) Cellwithtableview: (UITableView *) TableView
{
Static NSString *identifier=@ "QQ";
Yyfriendcell *cell=[tableview Dequeuereusablecellwithidentifier:identifier];
if (Cell==nil) {
This uses the system's own style
Cell=[[yyfriendcell Alloc]initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:identifier];
NSLog (@ "Create a Cell");
}
return cell;
}
-(void) Setfriends: (Yyfriendsmodel *) Friends
{
_friends=friends;
1. Set Avatar
Self.imageview.image=[uiimage Imagenamed:_friends.icon];
2. Set Nicknames
Self.textlabel.text=_friends.name;
3. Setup Introduction
Self.detailtextlabel.text=_friends.intro;
Judge whether it is a member
/**
* Here is a note, if not write else set to black, what will happen?
*/
if (_FRIENDS.ISVIP) {
[Self.textlabel Settextcolor:[uicolor Redcolor]];
}else
{
[Self.textlabel Settextcolor:[uicolor Blackcolor]];
}
Resize a font
Self.textlabel.font=[uifont SYSTEMFONTOFSIZE:15.F];
Self.detailtextlabel.font=[uifont SYSTEMFONTOFSIZE:10.F];
}
@end
YYHeaderView.h file
Copy Code code as follows:
//
YYHeaderView.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-6-1.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <UIKit/UIKit.h>
@class Yyqqgroupmodel,yyheaderview;
To discuss an agreement
@protocol yyheaderviewdelegate <NSObject>
-(void) Headerviewdidclickheaderview: (Yyheaderview *) Headerview;
@end
Copy Code code as follows:
@interface Yyheaderview:uitableviewheaderfooterview
@property (Nonatomic,strong) Yyqqgroupmodel *group;
Provides a class method to create a header view
+ (Instancetype) Headerwithtableview: (UITableView *) TableView;
Delegate comply with the Yyheaderviewdelegate protocol, you can use the method in the Protocol
@property (Nonatomic,weak) id<yyheaderviewdelegate> delegate;
@end
YYHEADERVIEW.M file
//
yyheaderview.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-6-1.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYHeaderView.h"
#import "YYQQGroupModel.h"
@interface Yyheaderview ()
@property (Nonatomic,strong) UIButton *btn;
@property (Nonatomic,strong) Uilabel *lab;
@end
Copy Code code as follows:
@implementation Yyheaderview
Create a custom header grouped view
+ (Instancetype) Headerwithtableview: (UITableView *) TableView
{
Static NSString *indentifier=@ "header";
First go to the cache pool to fetch the data
Yyheaderview *headerview=[tableview Dequeuereusablecellwithidentifier:indentifier];
If not, create it yourself
if (Headerview==nil) {
Headerview=[[yyheaderview Alloc]initwithreuseidentifier:indentifier];
}
Returns a header view
return headerview;
}
#warning Note that the frame set for the control in the construction method is not valid
-(ID) Initwithreuseidentifier: (NSString *) reuseidentifier
{
Initialize the constructor method in the parent class
if (Self=[super Initwithreuseidentifier:reuseidentifier]) {
Create a button
UIButton *btn=[uibutton Buttonwithtype:uibuttontypecustom];
Set the properties of a button
Set the background picture of the button in the normal state
[Btn setbackgroundimage:[uiimage imagenamed:@ "BUDDY_HEADER_BG"] forstate:uicontrolstatenormal];
Set the background picture of the button in the highlighted state
[Btn setbackgroundimage:[uiimage imagenamed:@ "buddy_header_bg_highlighted"] forstate:uicontrolstatehighlighted];
Set a small triangular picture on a button
[Btn setimage:[uiimage imagenamed:@ "Buddy_header_arrow"] forstate:uicontrolstatenormal];
Sets the alignment of information on a button to a left-aligned
Btn.contenthorizontalalignment=uicontrolcontenthorizontalalignmentleft;
Set the inner margin of a small triangular picture
Btn.contentedgeinsets=uiedgeinsetsmake (0, 20, 0, 0);
Sets the distance of text on a button from a small triangular picture
Btn.titleedgeinsets=uiedgeinsetsmake (0, 20, 0, 0);
Sets the text color of the grouped headings on the button (default is white)
[BTN Settintcolor:[uicolor Blackcolor]];
[btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];
Click event to add button
[Btn addtarget:self Action: @selector (Btnonclick:) forcontrolevents:uicontroleventtouchupinside];
Set the picture in BTN not fill the entire ImageView
Btn.imageView.contentMode = Uiviewcontentmodecenter;
Pictures out of range don't cut
Btn.imageView.clipsToBounds = NO;
Btn.imageView.layer.masksToBounds = NO;
Add a button to the view
[Self addsubview:btn];
SELF.BTN=BTN;
Create an Lab
Uilabel *lab=[[uilabel Alloc]init];
Set alignment of online numbers to right
Lab.textalignment=nstextalignmentright;
Set the number of online text color to Gray
Lab.textcolor=[uicolor Graycolor];
[Self Addsubview:lab];
Self.lab=lab;
}
return self;
}
-(void) Btnonclick: (UIButton *) btn
{
NSLog (@ "button clicked);
// Modify the IsOpen property of the model
//1. Modify model Data
Self.group.open=!self.group.isopen
//2. Refresh the form
//(the function of refreshing the table is completed by the controller, where you can set up a proxy), when the button is clicked, notify the agent to refresh the table
//Notification Agent
if ([Self.delegate respondstoselector: @selector ( Headerviewdidclickheaderview:)] {
[self.delegate Headerviewdidclickheaderview:self];
}
}
//When the control's frame value changes, the method is called automatically, so you can set the control's frame in the method;
-(void) layoutsubviews
{
#warning must not forget to invoke the method of the parent class
[Super Layoutsubviews];
& nbsp; //Set button frame and head view size
self.btn.frame=self.bounds;
//Set up Lab's frame
cgfloat padding=20;
cgfloat labw=50;
CGFloat labh=self.frame.size.height;
cgfloat laby=0;
cgfloat LABX=SELF.FRAME.SIZE.WIDTH-PADDING-LABW;
Self.lab.frame=cgrectmake (LABX, Laby, LABW, Labh);
}
#pragma mark-When a control is added to another view, the following methods are called
is called when it has been added to the parent view
-(void) Didmovetosuperview
{
NSLog (@ "added to view already");
In this way, you're about to get the latest head view added to TableView to modify its picture
if (Self.group.isOpen) {
Rotate the small triangle picture down
Self.btn.imageView.transform = Cgaffinetransformmakerotation (m_pi_2);
}
}
is about to be added to the parent view when it is called
-(void) Willmovetosuperview: (UIView *) Newsuperview
{
NSLog (@ "will be added to view");
}
Override the Get method to set the data
-(void) Setgroup: (Yyqqgroupmodel *) group
{
_group=group;
Set group headings
Self.btn.titlelabel.text=_group.name;
#warning Note that when you set the text of a button, be sure to set the state of the button, such as the above setting does not show
[Self.btn Settitle:_group.name Forstate:uicontrolstatenormal];
NSLog (@ "%@", Self.btn.titleLabel.text);
Set up online numbers
Self.lab.text=[nsstring stringwithformat:@ "%@/%d", _group.online,_group.friends.count];
}
@end
3. Controller part
YYViewController.h file
Copy Code code as follows:
//
YYViewController.h
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Yyviewcontroller:uitableviewcontroller
@end
YYVIEWCONTROLLER.M file
//
Yyviewcontroller.m
02-QQ buddy list (basic data loading)
//
Created by Apple on 14-5-31.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
#import "YYQQGroupModel.h"
#import "YYfriendCell.h"
#import "YYFriendsModel.h"
#import "YYHeaderView.h"
@interface Yyviewcontroller () <YYHeaderViewDelegate>
/**
* Used to hold all grouped data
*/
@property (Nonatomic,strong) Nsarray *groupfriends;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
#pragma mark-lazy Load
1. Get the data first, realize lazy load
-(Nsarray *) groupfriends
{
if (_groupfriends==nil) {
NSString *fullpath=[[nsbundle mainbundle]pathforresource:@ "Friends.plist" oftype:nil];
Nsarray *arraym=[nsarray Arraywithcontentsoffile:fullpath];
Nsmutablearray *models=[nsmutablearray ArrayWithCapacity:arrayM.count];
For (Nsdictionary *dict in Arraym) {
Yyqqgroupmodel *group=[yyqqgroupmodel Qqgroupmodelwithdict:dict];
[Models Addobject:group];
}
_groupfriends=[models copy];
}
return _groupfriends;
}
-(void) viewdidload
{
[Super Viewdidload];
Self.tableView.sectionHeaderHeight = 100;
}
To set up a data source #pragma mark-
How many groups are returned
-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView
{
return self.groupFriends.count;
}
How many rows are returned per group
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
Take out the corresponding group model
Yyqqgroupmodel *group=self.groupfriends[section];
Returns the number of friends in the corresponding group
return group.friends.count;
To judge here, if the group folds, return 0 rows, and if the group is open, return the actual number of rows
if (Group.isopen) {
return group.friends.count;
}else
// {
return 0;
// }
if (Group.isopen) {
Representative to expand
return group.friends.count;
}else
{
The representative wants to close.
return 0;
}
}
The contents of each set of rows
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath
{
1. Create a cell
Yyfriendcell *cell=[yyfriendcell Cellwithtableview:tableview];
2. Set up cell
Yyqqgroupmodel *group=self.groupfriends[indexpath.section];
Yyfriendsmodel *friends=group.friends[indexpath.row];
Cell.friends=friends;
3. Return a cell
return cell;
}
#pragma mark-Proxy method
//The method is invoked when a group header enters the field of view
-(UIView *) TableView: (UITableView *) TableView Viewforheader Insection: (nsinteger) Section
{
// // 1. Create a header view
// UIView *view = [[UIView alloc] init];
// view.backgroundcolor = [Uicolor Graycolor];
// // 2. Back to head view
// returns view;
//Create a custom header view
Yyheaderview *headerview=[yyheaderview Headerwithtableview:tableview];
//Set the current controller as Agent
headerview.delegate=self;
//Set header view data
Yyqqgroupmodel *groupmodel=self.groupfriends[section];
Headerview.group=groupmodel;
//back to Head view
return Headerview
}
#pragma mark-yyheaderviewdelegate
-(void) Headerviewdidclickheaderview: (Yyheaderview *) Headerview
{
To refresh data by calling the data source again
[Self.tableview Reloaddata];
}
Set the height of the header for a grouped header
-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section
{
return 30;
}
#pragma mark hides the status bar
-(BOOL) Prefersstatusbarhidden
{
return YES;
}
@end
Third, code description
1. Project Document Structure
2. Note the point
(1) Adjust the size of the font: Self.textlabel.font=[uifont SYSTEMFONTOFSIZE:15.F];
(2)-(void) Layoutsubviews method. This method is invoked when the frame of the control is changed, and this method is generally used to adjust the position of the child control, and it is important to call [Super Layoutsubviews];
(3) Every frame obtained in the Init method is 0;
(4) If the control does not display, there are some of the following error-arranging methods
A.frame is empty (no frame is set)
Whether the B.hidden is yes
c.alpha<=0.1 (transparency)
D. Not added to the parent control
E. View the parent control the above points
(5) Please note that when you set the text of the button, be sure to set the state of the button
Correct: [self.btn settitle:_group.name forstate:uicontrolstatenormal];
Error: Self.btn.titlelabel.text=_group.name;
(6) When invoking the construction method, it is necessary to initialize the method of the parent class first, then the initialization of its own property.
Self=[super Initwithreuseidentifier:reuseidentifier]
if (self)
{
......
}
(7) When a control is added to another view, the following methods are called
1 is called when it is added to the parent view-(void) Didmovetosuperview
2 will call-(void) Willmovetosuperview: (UIView *) when it is added to the parent view Newsuperview
(8) Picture filling knowledge
1) Set the picture in BTN not to fill the entire imageview btn.imageView.contentMode = Uiviewcontentmodecenter;
2 Pictures out of range do not cut
Btn.imageView.clipsToBounds = NO;
Btn.imageView.layer.masksToBounds = NO;
Iv. Supplement (agent)
Several steps to set up an agent
(1) If a button in a view is clicked, this time you need to refresh the data in the main controller. One way to do this is to have this view have the properties of the controller and then use that property to refresh the data when the button is clicked. Another approach is to set the controller as the proxy for this view, and when a button in the view is clicked, notify its agent (the primary controller) to do the refresh data.
(2) to be an agent is conditioned by the following steps
1. The Parties agree on a protocol (Agent agreement, note naming convention), customize a protocol in the view, and provide a method in the protocol.
Copy Code code as follows:
@protocol yyheaderviewdelegate <NSObject>
-(void) Headerviewdidclickheaderview: (Yyheaderview *) Headerview;
@end
2. Add an attribute variable of type ID in the view, anyone who follows the agreed agreement can be its agent.
Delegate comply with the Yyheaderviewdelegate protocol, you can use the method in the Protocol
Copy Code code as follows:
@property (Nonatomic,weak) id<yyheaderviewdelegate> delegate;
3. In the controller, following the custom proxy protocol, you can use the method provided by the agent to refresh the data in this method.
Copy Code code as follows:
@interface Yyviewcontroller () <YYHeaderViewDelegate>
-(void) Headerviewdidclickheaderview: (Yyheaderview *) Headerview
{
[Self.tableview Reloaddata];
}
4. Set the controller as the agent for the button click event.
headerview.delegate=self;