Cat Share, must boutique
Material code Address: http://blog.csdn.net/u013357243/article/details/44926809
Original address: Http://blog.csdn.net/u013357243?viewmode=contents
Look first.
Custom cell
本次主要是自定义Cell的学习 实现自定义Cell主要有三种方法:按照使用的频繁度排序: XIB > 纯代码 > StoryBoard
Steps for defining Xib
1> New Hmtgcell.xib
2> drag a control that needs to be customized, placing other child controls
3> Create a new class
* The class name should be consistent with Xib's name
* Inherit from subclass to match the type of root node in Xib
4> you need to change the root node class name of Xib to the newly created class name before you connect
5> Connection
6> in the Properties panel of the Xib, specify the reusable identifier
To create a cell by code
1> Create custom cell, inherit from UITableViewCell
2> determine the control as required, and define the properties
3> Use getter method to complete the instantiation of the control, only create and add to Contentview, do not handle the location
4> defines a model property that, through setter methods, sets the cell's display
Code Learning
首先加载字典神马的这些大家自己去代码里看吧,前面写了太多了。
Adjust the top bar
//ps:新建iOS交流学习群:304570962 //可以加猫猫QQ:1764541256 或则znycat //让我们一起努力学习吧。 //原文:http://blog.csdn.net/u013357243?viewmode=contents// 调整边距,可以让表格视图让开状态栏 self.tableView.contentInset = UIEdgeInsetsMake(20000);
Of the same effect:
/** 隐藏状态栏 */- (BOOL)prefersStatusBarHidden{ return YES;}
Data source method put the cell in.
#pragma mark-Data source methods- (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) section{return Self. TGS. Count;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{//1. Create a cellHmtgcell *cell = [Hmtgcell Cellwithtableview:tableview];//2. With the data model, you can set the cell content so that the view controller does not need to know the implementation details inside the cellCell. TG= Self. TGS[Indexpath. Row];returnCell;}
+ (Instancetype) Cellwithtableview: (UITableView*) tableview{//1. Reusable identifiers Static NSString*id = @"Cell";//2. TableView Query Reusable CellHmtgcell *cell = [TableView dequeuereusablecellwithidentifier:id];//3. If there is no reusable cell if(Cell = =Nil) {NSLog(@"Load Xib");//Load a custom view from Xibcell = [[[NSBundleMainbundle] loadnibnamed:@"Hmtgcell"OwnerNilOptionsNil] Lastobject]; }returnCell;} - (void) SETTG: (HMTG *) tg{///setter method, the first sentence is to be assigned, otherwise the model will be used in other methods, you cannot access the_TG = TG; Self. Titlelabel. Text= TG. Title; Self. IconView. Image= [UIImageImagenamed:tg. Icon]; Self. Pricelabel. Text= TG. Price; Self. Buycountlabel. Text= TG. Buycount;}
Note that in your own xib, the class is chosen, and then the connection is made to force
Methods provided by the template
#pragma the mark-template provides methodsThe /** initialization method is called when the cell is created using code, and this method is not called if you use Xib or storyboard.-(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier{self = [SuperInitwithstyle:style Reuseidentifier:reuseidentifier];if(self) {NSLog (@'%s ', __func__); }returnSelf;}/** is automatically called after it is loaded from xib, and will not be executed if pure code is used * /- (void) awakefromnib{NSLog (@'%s ', __func__); Self.contentView.backgroundColor = [Uicolor clearcolor];}/** cell is selected or unchecked it will be called. If the cell control is custom, all child controls should be added to Contentview */- (void) setselected: (BOOL) selected animated: (BOOL) animated{[SuperSetselected:selected animated:animated];if(selected) {Self.contentView.backgroundColor = [uicolor Redcolor]; }Else{Self.contentView.backgroundColor = [uicolor Greencolor]; }}
Define Proxy to Footer button implementation function (Analog network download)
First write the protocol in point H
#import <UIKit/UIKit.h>@class HMTgFooterView;@protocol HMTgFooterViewDelegate <NSObject>@optional/** 视图的下载按钮被点击 */- (void)tgFooterViewDidDownloadButtonClick:(HMTgFooterView *)footerView;@end@interface HMTgFooterView : UIView// 代理如果使用强引用,就会产生循环引用,造成控制器和子视图都无法被释放,造成内存泄露@property (nonatomic, weak) id <HMTgFooterViewDelegate> delegate;+ (instancetype)footerView;/** 刷新数据结束后,更新页脚的视图显示 */- (void)endRefresh;@end
Code for Point m file
////HMTGFOOTERVIEW.M//02-Group Purchase////Created by Apple on 14-8-21.//Copyright (c) 2014 itcast. All rights reserved.//#import "HMTgFooterView.h" @interface hmtgfooterview()@property(Weak,nonatomic)Iboutlet UIButton*loadmorebutton;@property(Weak,nonatomic)Iboutlet UIView*tipsview;@end @implementation hmtgfooterview + (Instancetype) footerview{return[[[NSBundleMainbundle] loadnibnamed:@"Hmtgfooterview"OwnerNilOptionsNil] Lastobject];} - (ibaction) loadmore{NSLog(@"Load More");//1. Hide button Self. Loadmorebutton. Hidden=YES;//2. Show Prompt View Self. Tipsview. Hidden=NO;//3.1 Determine if the agent implements the Protocol method if([ Self. DelegateRespondstoselector:@selector(Tgfooterviewdiddownloadbuttonclick:)]) { [ Self. DelegateTgfooterviewdiddownloadbuttonclick: Self]; }}/** View Controller Refresh completion Call method * /- (void) endrefresh{//4. Loading complete Data Self. Loadmorebutton. Hidden=NO; Self. Tipsview. Hidden=YES;}@end
The specific implementation of the agent is implemented by control, and then informs him
- (void) Tgfooterviewdiddownloadbuttonclick: (Hmtgfooterview *) footerview{//Get Data loading data on the simulated fetch network NSLog(@"Try to load the data ...."); Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (2.0* nsec_per_sec)), Dispatch_get_main_queue (), ^{//Actions to be taken after obtaining network data //Add data to the array to simulate the effect after the network load is complete nsdictionary*dict = @{@"title": @"haha", @"icon": @"Ad_00", @"Price": @"100.2", @"Buycount": @"+"}; Hmtg *TG = [Hmtg tgwithdict:dict];NSLog(@"Add data before%d", Self. TGS. Count); [ Self. TGSADDOBJECT:TG];NSLog(@"Add data after%d", Self. TGS. Count);//Refresh Data //[Self.tableview reloaddata]; //Create a new Indexpath Nsindexpath*path = [NsindexpathIndexpathforrow: ( Self. TGS. Count-1) Insection:0]; [ Self. TableViewInsertrowsatindexpaths:@[path] Withrowanimation:uitableviewrowanimationmiddle];//Notify footer view to adjust view display status[Footerview Endrefresh]; });}
- Footview = Controller to work, use agent
- Controller = Footview to work, directly call the Footview method can
Set head guess you like two lines up and down
This thing is very simple, is a custom xib that two lines is two high 1 pixels point of view, ———— Apple official also so, so do not question.
self.tableView.tableHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"HMTgHeadView" owner:nil options:nil] lastObject];
Special usage of the preprocessing directives # if 1
#if 0#endif
Can see the high function of the note, here will not let us see a green, but also can play the role of annotations, if you want to use this code to change 0 to 1,so easy!!
Characteristics of the proxy mode
Proxy mode features: is the parent control (view controller) that listens to the child control's events, and notifies the parent control to work when something happens to the child control!
PS: New iOS Exchange Learning Group: 304570962
You can add a cat qq:1764541256 or Znycat.
Let's study hard together.
Original: Http://blog.csdn.net/u013357243?viewmode=contents
Cat Learn iOS (16) UI Xib custom cell implementation Group Purchase UI