A small demmo that automatically refreshes the current time on Tableviewcell after a drop-down.
Create a new Uitableviewcontroller, initialize the variable, time, and Uirefreshcontrol in the Viewdidload, with the following code:
#import "TableViewController.h"
@interface Viewcontroller ()
@property (Nonatomic,strong) Nsmutablearray *logs;
@end
@implementation Viewcontroller
-(void) viewdidload{
[Super Viewdidload];
Self.logs=[nsmutablearray Alloc]init];
NSDate *date=[nsdate Alloc]init];
[Self.logs Addobject:date];
Initialize Uirefreshcontrol
Uirefreshcontrol *rc=[uirefreshcontrol Alloc]init];
The caption of the drop-down CONTROL
Rc.attributedtitle=[[nsattributedstring alloc]initwithstring:@ "drop-down refresh"];
Add Event
[RC addtarget:self Action: @selector (Refreshtableview) forcontrolevents:uicontroleventvaluechanged];
SELF.REFRESHCONTROL=RC;
}
The Refreshtableview method code is as follows:
-(void) refreshtableview{
if (self.refreshControl.refreshing) {
Self.refreshcontrol.attributedtitle=[[nsattributedstring alloc]initwithstring:@ "drop-down refresh"];
Add new Simulation Data
NSDate *date=[[nsdate Alloc]init];
[Self.logs Addobject:date];
[Self.refreshcontrol endrefreshing];
[Self.tableview Reloaddata];
}
Set Tableviewcell:
-(Nsinteger) Numberofsectionintableview: (uitableview*) tableview{
return 1;
}
-(Nsinteger) TableView: (uitableview*) TableView numberofrowsinsection: (Nsinteger) section{
return [self.logs Count];
}
-(uitableviewcell*) TableView: (uitableview*) TableView Cellforrowsindexpath: (nsindexpath*) indexpath{
Static nsstring *[email protected] "Cell";
UITableViewCell *cell=[tableview Dequeuereusablecellwithidentifier:cellidentifier];
if (Cell==nil) {
Cell=[[uitableviewcell alloc]initwithstyle:uitableviewcellsstylevalue1 Reuseidentifier:cellidentifier];
}
Nsdateformatter*dateformat=[[nsdateformatter Alloc]init];
[Self.dateformat setdateformat:@ "Yyyy-mmm-dd HH:mm:ss:zzz"];
Cell.tablelable.text=[dateformat stringfromdate:[self.logs Objectatindex:[indexpath Row]];
Cell.accessorytype=uitableviewcellaccessorydisclosureindicator;
return cell;
}
The final effect is as follows:
iOS simple drop-down refresh