IOS 学习笔记(Reminder, ActionSheetPicker)PART 13
公司项目于昨日上线了一个变更巨大的版本,论坛成功的被骂翻篇儿了。收入也跟着短期小爆发了一下,我只能说大家都尽力了,下面就爱JB咋咋地吧。上周为了这个功能点,大家周末全都没有休息,现在时刻有种,就要燃尽了的感觉。
MyEF已经正式提交审核了,它有很多可能无法通过审核的点,比如说:
- 需要和Chrome插件配合使用,亲,让人特意使用Chrome已经比较难了,谁还能要求人家必须使用对应的插件啊。
- Chrome本身就可能成为一个问题,毕竟是竞争对手的产品,如果是Safari插间则另当别论。
- 非EF学员就只能用字典。
- 字典依赖EF接口,同时存在爬取行为。
- 我并未针对7.0以下的系统做测试。
但无论如何,它都是我学习iOS开发以来的第一份作业,我的心情从提交上去那一刻开始,就已经松了一口气了。
继续记录开发过程中的一些学习点:
ActionSheet Picker

为程序添加一个从下方划入的选项面板,需要用到UIActionSheet,用法如下:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Remind me 4 hours ago"
otherButtonTitles:@"Remind me 1 day ago",nil];
[actionSheet showInView:self.view];
然后实现对应的Delegate,UIActionSheetDelegate,
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
//do something with index 0;
}else if(buttonIndex == 1){
//do something with index 1;
}
}
因为想快速达成目的,所以较为复杂的ActionSheet控件我使用了一个GitHub上的开源项目,见这里,由于代码比较老,我更新了部分内容。
实现的效果是这样的:

Reminder
将提示信息添加到iOS的Reminder是一个很方便实用的功能,所以我就这么做了,代码如下:
- (void)addAReminder:(int)type {
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
if (granted) {
EKReminder *reminder = [EKReminder reminderWithEventStore:store];
reminder.calendar = [store defaultCalendarForNewReminders];
NSString *startTime = [self.startAndEndTimeLabel.text componentsSeparatedByString:@"-"][0];
NSDate *date;
if (type == 1) {
reminder.title = [NSString stringWithFormat:@"EF Course Tomorrow:%@",self.startAndEndTimeLabel.text ];
startTime = [NSString stringWithFormat:@"%@ %@",self.dateLabel.text,startTime ];
NSDate *startedDate = [self.formatter dateFromString:startTime];
date = [NSDate dateWithTimeInterval:-86400 sinceDate:startedDate];
}else
{
reminder.title = [NSString stringWithFormat:@"EF Course 4 hours later:%@",self.startAndEndTimeLabel.text ];
startTime = [NSString stringWithFormat:@"%@ %@",self.dateLabel.text,startTime ];
NSDate *startedDate = [self.formatter dateFromString:startTime];
date = [NSDate dateWithTimeInterval:-14400 sinceDate:startedDate];
}
EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:date];
[reminder addAlarm:alarm];
NSError *error = nil;
[store saveReminder:reminder commit:YES error:&error];
if(error)
NSLog(@"unable to Reminder!: Error= %@", error);
}
}];
}
昨天晚上,在各种不爽之后,我怒过了一级英语,顺利进入7级,在逆流而上的时候如果自己不鼓励自己,还有谁能帮你。
