前言:一個仿約單需求分類(帶有QQ好友清單的效果),并可以回到頂部
先來個效果圖
首先是資料源
#pragma mark 初始化資料
- (void)initDataSource
{
//讀取本地檔案
NSString *file = [[NSBundle mainBundle] pathForResource:@"category.plist" ofType:nil];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:file];
YDDTResult *result = [YDDTResult objectWithKeyValues:dict];
NSMutableArray *tempArray = (NSMutableArray *)result.demandTemplateCategory;
for (YDDTTopCategory *dtc in tempArray) {
NSMutableArray *ttArray = [NSMutableArray array];
for (YDDTSubCategory *dt in result.demandTemplate) {
if ([dtc.template_category_id isEqualToString:dt.template_category_id]) {
[ttArray addObject:dt];
}
}
dtc.status = 1;
dtc.demandTemplates = ttArray;
}
_dsCategoryArray = tempArray;
}
其次是修改狀态,用于判斷收起還是展開
- (void)clickTitle:(UIGestureRecognizer *)recognizer
{
NSInteger section = recognizer.view.tag - KHeaderViewTag;
YDDTTopCategory *dtc = _dsCategoryArray[section];
if (dtc.status == 1) {
dtc.status = 0;
}else {
dtc.status = 1;
}
[_dsTableView reloadData];
}
通過 scrollViewDidScroll來判斷是否顯示回到頂部的按鈕
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y > (self.view.frame.size.height/15)) {
_topBtn.hidden = NO;
}else {
_topBtn.hidden = YES;
}
}
詳細的話,大家看demo。
demo連結:http://download.csdn.net/detail/u011154007/9674245