用于快速构建设置界面 UITableView 子类:XFSettings

jopen 9年前

使用 UITableViewController 为基类,用于快速构建设置界面,可定制性强,有多个 cell 类型缓存重用,扩展性强,可继承 XFSettingCell 或功能更强大的 XFSettingInfoCell 作为父类进行自定义样式,采用 JOSN 进行布局和对功能的添加。

用于快速构建设置界面 UITableView 子类:XFSettings

代码示例:

//.h  #import "XFSettings.h"  @interface ViewController : XFBaseSettingTableViewController  @end  //.m  @interface ViewController ()<XFBaseSettingDataSource>  @end  @implementation ViewController  - (void)viewDidLoad {      [super viewDidLoad]; // must invoke super method.      self.navigationItem.title = @"设置";      self.view.backgroundColor = [UIColor whiteColor];      self.dataSource = self; // set self as dataSource.  }  - (NSArray *)settingItems  {      return @[ // groupArr               @{ // groupModel                   XFSettingGroupHeader: @"基本信息",                   XFSettingGroupItems : @[ // items                           @{ // itemModel                               XFSettingItemTitle: @"我的朋友",                               XFSettingItemIcon : @"1435582804_group",                               XFSettingItemClass : [XFSettingInfoItem class], // 这个字段用于判断是否有右边辅助功能的cell,不写则没有                               XFSettingItemAttrDetailText : @"你的好友",                               XFSettingItemRelatedCellClass:[XFSettingInfoDotCell class],// 自定义的cell                               XFSettingItemDestViewControllerClass : [XFNewFriendViewController class], // 如果有目标控制器                               XFSettingOptionActionBlock : ^(XFSettingInfoCountCell *cell,XFSettingPhaseType phaseType,id intentData){ // 如果有可选的操作                                   if (phaseType == XFSettingPhaseTypeCellInteracted) {                                       cell.rightInfoLabel.hidden = YES;                                   }                               }                               },// end itemModel                           @{                               XFSettingItemTitle: @"我的消息",                               XFSettingItemIcon : @"1435527299_message",                               XFSettingItemClass : [XFSettingInfoItem class],                              XFSettingItemAttrDetailText : @"新的好友",                               XFSettingItemAttrRightInfo : @"3",                               XFSettingItemRelatedCellClass:[XFSettingInfoCountCell class],                               XFSettingOptionActionBlock : ^(XFSettingInfoCountCell *cell,XFSettingPhaseType phaseType,id intentData){                                   // 交互时处理                                   if (phaseType == XFSettingPhaseTypeCellInteracted) {                                       int count = cell.rightInfoLabel.text.intValue;                                       cell.rightInfoLabel.text = [NSString stringWithFormat:@"%d",++count];                                   }                               }                               },                           @{                               XFSettingItemTitle: @"缓存大小",                               XFSettingItemIcon : @"1435529531_CD-DVD Drive-2",                               XFSettingItemClass : [XFSettingInfoItem class],                               XFSettingItemAttrDetailText : @"cache",                               XFSettingItemAttrRightInfo : @"正在计算",                               XFSettingItemRelatedCellClass:[XFSettingInfoCell class],                               XFSettingOptionActionBlock : ^(XFSettingInfoCell *cell,XFSettingPhaseType phaseType,id intentData){                                   [self cacheDirClear:cell phaseType:phaseType];                               }                               },                           @{                               XFSettingItemTitle: @"保存我的设置",                               XFSettingItemIcon : @"1435527366_1-8",                               XFSettingItemClass : [XFSettingSwitchItem class],                               XFSettingOptionActionBlock : ^(XFSettingCell *cell,XFSettingPhaseType phaseType,id intentData){                                   if (phaseType == XFSettingPhaseTypeCellInteracted) {                                       if ([intentData[XFSettingIntentDataSwitchOn] boolValue]) {                                           NSLog(@"%@", @"保存");                                       }else{                                           NSLog(@"%@", @"取消保存");                                       }                                   }                               }                               },                           @{                               XFSettingItemTitle: @"检测新版本",                               XFSettingItemIcon : @"1435529156_cloud-arrow-up",                               // 使用自定义向右箭头                               XFSettingItemArrowIcon : @"CellArrow",                               XFSettingItemClass : [XFSettingInfoItem class],                               XFSettingItemRelatedCellClass:[XFSettingInfoCell class],                               XFSettingItemAttrRightInfo : @"有新版本!",                               XFSettingItemDestViewControllerClass : [UpdateViewController class],                               XFSettingOptionActionBlock : ^(XFSettingInfoCell *cell,XFSettingPhaseType phaseType,id intentData){                                   // 自定义初始化样式                                   if (phaseType == XFSettingPhaseTypeCellInit) {                                       cell.rightInfoLabel.textColor = [UIColor orangeColor];                                   }                               }                               },                           @{                               XFSettingItemTitle: @"vip帮助",                               XFSettingItemIcon : @"1435529211_circle_help_question-mark",                               XFSettingOptionActionBlock : ^(XFSettingCell *cell,XFSettingPhaseType phaseType,id intentData){                               }                               }                           ],                   XFSettingGroupFooter : @"lalala~"                   }// end groupModel               ];// endgroupArr  }  @end

项目主页:http://www.open-open.com/lib/view/home/1440247327661