One, simple-agent process
1, create an agent
@class Tgfootview;
@protocol tgfootviewdelegate <NSObject>
@optional Optional whether to implement
The download button for the view is clicked
-(void) Tgfootviewdiddownloadbuttonclick: (Tgfootview *) Footview;
@end
@interface Tgfootview:uiview
If a proxy uses a strong reference, a circular reference is generated, causing the controller and child views to be freed, causing a memory leak.
@property (nonatomic,weak) ID <TgFootViewDelegate> delegate;
@end
2. Compliance with agreements
<TgFootViewDelegate>
3, setting up the proxy
View controller becomes a proxy for footer
Footer.delegate = self;
4, the controller implements the proxy method
-(void) Tgfootviewdiddownloadbuttonclick: (Tgfootview *) Footview
{
}
5, determine whether the agent implements the Protocol method
if ([Self.delegate respondstoselector: @selector (Tgfootviewdiddownloadbuttonclick:)]) {
Perform
[Self.delegate tgfootviewdiddownloadbuttonclick:self];
}
Ii. several agent methods of UITableView
1, as long as the implementation of this method, will be able to support gesture drag Delete, delete the need to do their own!
Uitableviewcelleditingstylenone,
Uitableviewcelleditingstyledelete, deleting
Uitableviewcelleditingstyleinsert add
-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath
{
if (Editingstyle = = Uitableviewcelleditingstyledelete) {
NSLog (@ "to delete");
MVC = data is stored in the model
1. Delete the Indexpath data in Self.datalist
[Self.datalist RemoveObjectAtIndex:indexPath.row];
NSLog (@ "%@", self.datalist);
2. Refresh the table (reload the data)
Reload all data
[Self.tableview Reloaddata];
Deleterowsatindexpaths to animate a table control to delete a specified row
[Self.tableview Deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationmiddle];
} else if (Editingstyle = = Uitableviewcelleditingstyleinsert) {
NSLog (@ "To add data");
1. Adding data to an array
[Self.datalist insertobject:@ "Wangxiao" AtIndex:indexPath.row + 1];
2. Refresh the table
[Self.tableview Reloaddata];
Insertrowsatindexpaths the Table control animation to add the specified row in the specified Indexpath
Create a new Indexpath
Nsindexpath *path = [Nsindexpath IndexPathForRow:indexPath.row + 1 inSection:indexPath.section];
[Self.tableview Insertrowsatindexpaths:@[path] withrowanimation:uitableviewrowanimationmiddle];
}
}
2. As long as you implement this method, you can display the drag control
-(void) TableView: (UITableView *) TableView Moverowatindexpath: (Nsindexpath *) Sourceindexpath Toindexpath: ( Nsindexpath *) Destinationindexpath
{
Interface Data UITableView has been completed.
Adjusting the data can
[Self.datalist ExchangeObjectAtIndex:sourceIndexPath.row WithObjectAtIndex:destinationIndexPath.row];
1. Remove the source from the array
ID Source = Self.datalist[sourceindexpath.row];
2. Remove the source from the array
[Self.datalist RemoveObjectAtIndex:sourceIndexPath.row];
NSLog (@ "%@", self.datalist);
3. Insert the source into the array at the target location
[Self.datalist Insertobject:source AtIndex:destinationIndexPath.row];
NSLog (@ "%@", self.datalist);
}
3, return to edit style, if not implement this method, the default is to delete
-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) Indexpath
{
if (indexpath.row% 2) {
return uitableviewcelleditingstyleinsert;
} else {
return uitableviewcelleditingstyledelete;
}
return uitableviewcelleditingstyleinsert;
}
4,cell will be called when it is selected or unchecked
If you are a custom cell control, all child controls should be added to the Contentview
-(void) setselected: (BOOL) selected animated: (bool) Animated {
[Super setselected:selected animated:animated];
Configure The view for the selected state
if (selected) {
Self.contentView.backgroundColor = [Uicolor Redcolor];
} else {
Self.contentView.backgroundColor = [Uicolor Greencolor];
}
}
5, refresh the data
1, [Self.tableview reloaddata];
2, create a new Indexpath
Nsindexpath *path = [Nsindexpath indexpathforrow:self.tgs.count-1 insection:0];
Add to
[Self.tableview Insertrowsatindexpaths:@[path] withrowanimation:uitableviewrowanimationmiddle];
Roll to the end.
[Self.tableview Scrolltorowatindexpath:path Atscrollposition:uitableviewscrollpositionbottom Animated:YES];
6,
Self.tableView.tableHeaderView = [[[NSBundle Mainbundle] loadnibnamed:@ "Headerview" Owner:nil Options:nil] Lastobject ];
2015/10/4 IOS Note details Simple-agent process UITableView