我不知道如何让用户选择本地通知的重复间隔。我已经链接到两个详细描述问题的图像。
This is the image of the file where I need to insert the choose from the segmented control
And this is the image of the file where the segmented control is placed.
发布于 2016-06-20 19:41:50
我查看了您的代码,一种解决方案是将segmentedControl的值作为参数添加到TodoItem中,就像您现在已经在gentag参数中所做的那样。
然后,在您的addItem方法中,您只需要将您现在拥有的Int值转换为一个可以传递给notification.repeatInterval的NSCalendarUnit。
为了保持这一点,您可以创建一个知道如何从Int值转换为NSCalendarUnit值的新Enum,然后您的gentag参数就可以是这种类型。
因此,在你拥有TodoSchedulingViewController的文件中,你可以在文件的顶部写下类似这样的代码:
import UIKit
enum RepeatInterval: Int {
case None = 0
case Daily = 1
case Weekly = 2
func toCalendarUnit() -> NSCalendarUnit {
switch self {
case .None:
return NSCalendarUnit(rawValue: 0)
case .Daily:
return NSCalendarUnit.Day
case .Weekly:
return NSCalendarUnit.Weekday
}
}
}
class TodoSchedulingViewController: UIViewController {
...然后您可以像这样使用它:
在你的ViewController中
let todoItem = TodoItem(deadline:....,
title:....,
gentag: RepeatInterval(rawValue: segmentedControl.selectedSegmentIndex)!, //You can force unwrap here, because you know the value is always one you get from your segmentedControl
UUID......)在您的TodoList类中:
...
notification.userInfo = ["title" : item.title, "UUID" : item.UUID]
notification.repeatInterval = item.gentag.toCalendarUnit()希望这是有意义的。
Oh...and下次,请发布您的实际代码而不是图像,这样可以更容易地快速了解正在发生的事情,并更快地将代码片段复制到答案中:)
https://stackoverflow.com/questions/37918528
复制相似问题