我正在使用swift在xcode中创建一个rss阅读器。我正在关注此事 https://www.youtube.com/watch?v=jootsUaCvAU ,但是他并没有为用户添加自己的多个Feed。它们是一个滑出式菜单,但它们只是一个“添加提要”按钮,用户可以添加自己的提要。我已经将其取出,并使用“feedNames.append()将其他提要名称放在幻灯片菜单上“,但我现在需要的是,在用户点击幻灯片菜单上的某个Feed名称后,Feed会打开。我想我知道代码在哪里,但我不知道该放什么。以下是带有项目的滑出菜单的代码。代码仍然实现了“添加提要”,但只是忽略它,因为我将把它拿出来。
func sideBarDidSelectMenuButtonAtIndex(index: Int) {
if index == 0{ // ADD FEED BUTTON
let alert = UIAlertController(title: "Add new feed", message: "Enter feed name and URL", preferredStyle: UIAlertControllerStyle.Alert)
alert.addTextFieldWithConfigurationHandler({ (textField:UITextField!) -> Void in
textField.placeholder = "Feed name"
})
alert.addTextFieldWithConfigurationHandler({ (textField:UITextField!) -> Void in
textField.placeholder = "Feed URL"
})
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.Default, handler: { (alertAction:UIAlertAction!) -> Void in
let textFields = alert.textFields
let feedNameTextField = textFields?.first as UITextField
let feedURLTextField = textFields?.last as UITextField
if feedNameTextField.text != "" && feedURLTextField.text != "" {
let moc = SwiftCoreDataHelper.managedObjectContext()
let feed = SwiftCoreDataHelper.insertManagedObject(NSStringFromClass(Feed), managedObjectConect: moc) as Feed
feed.name = feedNameTextField.text
feed.url = feedURLTextField.text
SwiftCoreDataHelper.saveManagedObjectContext(moc)
self.loadSavedFeeds()
}
}))
所以我确定,代码在这里,但我不确定要放什么。谢谢你的帮助!
答案 0 :(得分:0)
func sideBarDidSelectMenuButtonAtIndex(index: Int)
if index == 0{
let url = NSURL(string: "http://www.widadclub.tk/feed")
let feedParser = MWFeedParser(feedURL: url)
feedParser.delegate = self
feedParser.parse()
}