No more nonsense to say, directly to everyone paste code.
The specific code looks like this:
#import "ViewController.h" #import "TuanGouModel.h" #import "TuanGouTableViewCell.h" #define Kdevicewidth [UIScreen Mainscreen].bounds.size.width #define Kdeviceheight [UIScreen mainscreen].bounds.size.height @interface Viewcontroller () <UITableViewDelegate,UITableViewDataSource,UISearchResultsUpdating> {Uisearchcontroller * _
Sscller;
} @property (Nonatomic,strong) nsmutablearray* secarrm;
@property (Nonatomic,strong) nsmutablearray* tuangouarrm;
@property (Nonatomic,strong) uitableview* myTable;
@end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload];
[Self Createna];
Self.myTable.backgroundColor = [Uicolor Lightgraycolor];
[Self CREATESECB];
[Self Setuprefresh];
Self.title = @ "Gourmet"; #pragma mark-navigation-(void) createna{uibarbuttonitem *rightitem = [[Uibarbuttonitem alloc]initwithtitle:@ ' Edit ' Style:uib
Arbuttonitemstyleplain target:self Action: @selector (Tableedit:)];
Self.navigationItem.rightBarButtonItem = Rightitem;
Self.title = @ "Gourmet"; //Click the Edit button on the right side of the navigation so that the table canEdit-(void) Tableedit: (Uibarbuttonitem *) btnitem{//if (self.myTable.editing = no) {//Not in edit state, navigation button text is ' edit '////click '
Edit the text so that the table is edited and the text of the button is modified to "done"//self.myTable.editing = YES;
}else{////Edit state, click "Done" button, cancel the edit status of the table, modify the navigation button text as "edit"//self.myTable.editing = NO;//Btnitem.title = @ "edit";
Self.navigationItem.rightBarButtonItems = @[btnitem]; }-(void) createsecb{_sscller = [[Uisearchcontroller Alloc]initwithsearchresultscontroller:nil]; _
Sscller.searchresultsupdater = self;
Self.myTable.tableHeaderView = _sscller.searchbar; }-(Nsmutablearray *) secarrm{if (_secarrm = = nil) {return _SECARRM = [Nsmutablearray array];}
else{return _SECARRM}} -(void) didreceivememorywarning {[Super didreceivememorywarning];} #pragma mark-table lazy Load-(UITableView *) mytable{if (_my Table = = nil) {_mytable = [[UITableView alloc]initwithframe:cgrectmake (,, Kdevicewidth, Kdeviceheight) Style:uitablevie
Wstyleplain];
[Self.view addsubview:_mytable];
_mytable.delegate = self; _mytaBle.datasource = self;
_mytable. Separatorstyle = uitableviewcellseparatorstylesinglelineetched;
return _mytable;
#pragma mark-Group purchase data lazy load-(Nsmutablearray *) tuangouarrm{if (_tuangouarrm = = nil) {_TUANGOUARRM = [Nsmutablearray array];
nsstring* Plistpath = [[NSBundle mainbundle]pathforresource:@ "Tgs.plist" oftype:nil];
nsarray* Tuanarr = [Nsarray Arraywithcontentsoffile:plistpath];
For (nsdictionary* dict in Tuanarr) {tuangoumodel* model =[[tuangoumodel alloc]initwithdict:dict];
[_tuangouarrm Addobject:model];
} return _TUANGOUARRM; #pragma mark-Data source protocol-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{if (_
sscller.active) {//Search results form return self.secArrM.count;} else{return self.tuanGouArrM.count;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexPath{//Registration [
TableView Registerclass:[tuangoutableviewcell class] forcellreuseidentifier:@ "Tuancell"]; Reset tuangoutableviewcell* cell = [tablEview dequeuereusablecellwithidentifier:@ "Tuancell" Forindexpath:indexpath];
Cell.backgroundcolor = [Uicolor Yellowcolor];
Selected Style Cell.selectionstyle = Uitableviewcellselectionstylenone; if (!_sscller.active) {Cell.tuangoumodel = Self.tuangouarrm[indexpath.row];}
else{//Search results Cell.tuangoumodel = Self.secarrm[indexpath.row];} return cell; #pragma Mark-tablev Protocol-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return}-(void) Updatesearchresultsforsearchcontroller: (Uisearchcontroller *) searchcontroller{[
SELF.SECARRM Removeallobjects];
for (int j =; J < _tuangouarrm.count; J + +) {tuangoumodel* model =[[tuangoumodel alloc]init]; model = _tuangouarrm[j];
if ([Model.title isequaltostring: _sscller.searchbar.text]) {[Self.secarrm Addobject:model];}}
[Self.mytable Reloaddata];
}//Allow menu-(BOOL) TableView: (UITableView *) TableView Shouldshowmenuforrowatindexpath: (Nsindexpath *) Indexpath {
return YES; //Each cell can be clicked to appear menu-(BOOL) tAbleview: (UITableView *) TableView canperformaction: (SEL) Action Forrowatindexpath: (Nsindexpath *) Indexpath Withsender: (ID) sender {return YES;}-(void) TableView: (UITableView *) TableView performaction: (SEL) action Forrowatindexpath: (Nsindexpath *) Indexpath Withsender: (ID) sender{NSLog (@ "long press"); if (action = = @selector (copy:)) {NSLog
(@ "copy"); } if (action = = @selector (cut:)) {NSLog (@ ' cut ');} if (action = = @selector (paste:)) {NSLog (@ "paste");} if (action = = @sele
ctor (SelectAll:)) {NSLog (@ "SelectAll");} Pull load-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (
Nsindexpath *) indexpath{if (Indexpath.row = = Self.tuanGouArrM.count-) {NSLog (@ "last line");
tuangoumodel* model =[[tuangoumodel Alloc]init];
Model = _tuangouarrm[arcrandom ()%];
[_tuangouarrm Addobject:model];
[Self.mytable Reloaddata];
}//dropdown refresh-(void) Setuprefresh {//. Add Refresh Control Uirefreshcontrol *control=[[uirefreshcontrol Alloc]init]; [Control addtarget:self Action: @selector (RefreshStateChange:) forcontrolevents:uicontroleventvaluechanged];
[Self.mytable Addsubview:control];
Immediately enters the refresh state and does not trigger the Uicontroleventvaluechanged event [Control beginrefreshing];
. loading data [self refreshstatechange:control]; /** * Uirefreshcontrol into Refresh state: Load Latest data/-(void) Refreshstatechange: (Uirefreshcontrol *) control {tuangoumodel* Model =[
[Tuangoumodel Alloc]init];
Model = _tuangouarrm[arcrandom ()%];
[_tuangouarrm Insertobject:model Atindex:];
[Self.mytable Reloaddata];
NSLog (@ "first line");
[Control endrefreshing]; //Indicates whether to allow highlighting of selected rows-(BOOL) TableView: (UITableView *) TableView Shouldhighlightrowatindexpath: (Nsindexpath *) Indexpath
{return YES;} Select a row to perform-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{NSLog (@ "
Selected:%ld, row:%ld ", Indexpath.section, Indexpath.row); On//Unchecked, this method is often invoked when a table allows multiple selections-(void) TableView: (UITableView *) TableView Diddeselectrowatindexpath: (Nsindexpath *) indexpath{NSLog (@ "deselected:%ld, Row:%ld", Indexpath.section, indexpath.roW); }
The above code is hi small set for you to introduce the development of iOS UITableView and Uisearchcontroller implementation of search and pull load, Drop-down Refresh instance code, I hope to help!