勤之时 - 表示层(四)

2017-05-18  本文已影响102人  启发禅悟

应用很早就上线了,欢迎大家下载使用:http://itunes.apple.com/app/id1206687109

源码已经公开,大家可以去https://github.com/Inspirelife96/ILDiligence下载。 喜欢的话Fork或者给个Star,非常感谢。

下面是这一系列的全部帖子:
想法和原型
勤之时 - 架构与工程组织结构
勤之时 - 数据持久层的实现
勤之时 - 网络层的实现
勤之时 - 业务逻辑层
勤之时 - Info.plist的改动
勤之时 - 表示层(一)
勤之时 - 表示层(二)
勤之时 - 表示层(三)
勤之时 - 表示层(四)
勤之时 - 表示层(五)

因为某些事情,耽搁了好久。总算可以开始把这个内容给补全了。希望接下来的一周能把这个应用的开发过程描述完毕,并把源码公开给大家。

这一节讲任务设置的部分,左上角的按钮对应的功能。

功能描述如下:

【任务一览】 View Controller


任务一览

【任务设置】View Controller


任务设置.png

【任务设置详细】View Controllers


任务设置详细.png

【添加任务】View Controller


添加任务.png

MVC设计考虑:
在编写这个功能的时候,我个人会觉得非常的杂乱,因为它们是一系列类似但又有细微差别的View Controller,每一个单独写吧,总会有那么一部分的代码会重复,抽取一些公共内容吧,也总有一些别扭。 所以,如果大家有好的意见建议,请指教。
最终的考虑


任务设置MVC设计考虑.png

详细编码:
ILDTaskConfigurationViewController 有两种风格,即【任务设置】和【添加任务】风格

typedef NS_ENUM(NSInteger, TaskConfigurationType) {
    TaskConfigurationTypeAdd,
    TaskConfigurationTypeModify
};

因此,对导航左右按钮的操作会有所不同,同时考虑到此时需要保存任务设置的内容。

- (void)clickBackBarButtonItem:(id)sender {
    if (self.configurationType == TaskConfigurationTypeModify) {
        if ([self.taskConfiguration.name isEqualToString:@""]) {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"警告" message:@"任务名称不能为空,请设置" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"知道" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                //
            }];
            
            [alertVC addAction:cancelAction];
            
            [self presentViewController:alertVC animated:YES completion:nil];
        } else {
            [[ILDTaskDataCenter sharedInstance] updateTask:self.taskId taskConfiguration:self.taskConfiguration];
            [super clickBackBarButtonItem:sender];
        }
    } else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
- (void)clickRightButtonItem:(id)sender {
    if (self.configurationType == TaskConfigurationTypeAdd) {
        [[ILDTaskDataCenter sharedInstance] addTask:self.taskConfiguration];
        [self dismissViewControllerAnimated:YES completion:nil];
    } else {
        if ( [[[ILDTaskDataCenter sharedInstance] taskIds] count] <= 1) {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"通知" message:@"这是最后一个任务,无法被删除" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                //
            }];
            
            [alertVC addAction:cancelAction];
            
            [self presentViewController:alertVC animated:YES completion:nil];
        } else {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"警告" message:@"该操作会删除当前任务以及所有的和任务相关的统计记录,确认删除吗?" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [[ILDTaskDataCenter sharedInstance] removeTask:self.taskId];
                [self.navigationController popViewControllerAnimated:YES];
            }];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                //
            }];
            
            [alertVC addAction:cancelAction];
            [alertVC addAction:okAction];
            
            [self presentViewController:alertVC animated:YES completion:nil];
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读