LISettingArrowItem.m:
+ (instancetype)itemWithIcon:(NSString *)icon title:(NSString *)title destVcClass:(Class)destVcClass
{
ILSettingArrowItem *item = [super itemWithIcon:icon title:title];
item.destVcClass = destVcClass;
return item;
}
LISettingItem.增加block,增加功能:
#import <Foundation/Foundation.h>
typedef void(^ILSettingItemOption)();
@interface ILSettingItem : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *icon;
// 保存一段功能,在恰当的时候调用
@property (nonatomic, copy) ILSettingItemOption option;
+ (instancetype)itemWithIcon:(NSString *)icon title:(NSString *)title;
@end
ILSettingTableViewController.m,增加取消选中,和处理新功能:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 取消选中
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// 取出模型
ILSettingGroup *group = self.dataList[indexPath.section];
ILSettingItem *item = group.items[indexPath.row];
// 执行操作
if (item.option) {
item.option();
return;
}
if ([item isKindOfClass:[ILSettingArrowItem class]]) { // 需要跳转控制器
ILSettingArrowItem *arrowItem = (ILSettingArrowItem *)item;
// 创建跳转的控制器
if (arrowItem.destVcClass) {
UIViewController *vc = [[arrowItem.destVcClass alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
}
}
产品更新:
导入第三方库
LISettingTableViewController.m中:
LISettingItem *newVersion = [LISettingArrowItem itemWithIcon:@"MoreUpdate" title:@"检查新版本"];
// 保存了一段检查更新的功能
newVersion.option = ^{
// 1.显示蒙板
[MBProgressHUD showMessage:@"正在检查ing......."];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 2.隐藏蒙板
[MBProgressHUD hideHUD];
// 3.提示用户
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"有更新版本" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"立即更新", nil];
// 显示UIAlertView
[alert show];
});
};