这个是也是看了人家的代码,觉得甚是简单清晰,也是比较容易扩展。拿来学习一下

效果展示:

iOS 结构简单清晰的 设置页面-LMLPHP

重点有以下2处:
1 .建立groupModel
列清组元素:当前组list 集合, 是否有header 或者 footer  等属性元素
@interface HFSettingGroup : NSObject

@property (nonatomic, strong) NSString *header; // 头部标题

@property (nonatomic, strong) NSString *footer; // 尾部标题

@property (nonatomic, strong) NSArray *items; // 中间的条目

@end
2 .  建立itemModel 
 
列清list 每行的item 都有什么元素

通常有的 就是 icon, title,content  。根据具体问题具体分析处理

添加闭包属性 void (^operation)() 根据具体 didSelectRowAtIndexPath: 触发获取指定回调

如果UI个性化非常明显,应该根据该组的枚举类型定制个人性化

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, HFSettingItemStyle){
HFSettomgStyleNormal //普通类型
}; @interface HFSettingItem : NSObject @property (nonatomic, assign) HFSettingItemStyle style; //类型style
@property (nonatomic, strong) NSString *icon; //左边图标
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *content; // 描述
//具体样式的设置 如果格式不复杂 可区分成枚举Type 归类UI形式 这里UI有点复杂 不用Type
@property (nonatomic, strong) NSNumber *isRedPointHidden; //代表当前是否未读
@property (nonatomic, strong) NSNumber *isLineHidden; //是否展示底部线
@property (nonatomic, strong) NSNumber *isArrowHidden; //是否展示箭头
/** cell上相关的触发事件 */
@property (nonatomic, copy) void (^operation)() ; // 点击cell后要执行的操作 /**
创建通用 settingItem @param icon 左边图标
@param title title
@param content content
@return item
*/
+ (id)itemWithIcon:(NSString *)icon title:(NSString *)title content:(NSString *)content; @end

3 .使用举例

- (void)addSectionItems
{
self.groupArrays = [NSMutableArray array];
__weak typeof(self) weakSelf = self;
// 1.1.月经测试
HFSettingItem *test = [HFSettingItem itemWithIcon:nil title:@"月经测试" content:@"未测试"];
//cell点击事件
test.operation = ^{
//TODO: test
NSLog(@"test");
};
// 1.2测试结果
HFSettingItem *result = [HFSettingItem itemWithIcon:nil title:@"测试结果" content:@"平和质"];
result.operation = ^{
//TODO: test
NSLog(@"result");
TestViewController *vc = [TestViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}; HFSettingGroup *group = [[HFSettingGroup alloc] init];
group.header = @"第一组";
group.items = @[test,result];
[self.groupArrays addObject:group]; // 2.1意见反馈
HFSettingItem *suggest = [HFSettingItem itemWithIcon:nil title:@"意见反馈" content:nil];
suggest.operation = ^{
NSLog(@"suggest");
TestViewController *vc = [TestViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}; HFSettingGroup *group1 = [[HFSettingGroup alloc] init];
group1.items = @[suggest];
group1.header = @"第二组";
[self.groupArrays addObject:group1];
}
05-11 14:05