- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经搜索了每个地方来找到我遇到的这个错误的解决方案,我还尝试使用 nsuserdefaults、struct 和全局变量将我的变量传递给其他 View Controller 。我正在使用 mmdrawer,并且在我的第一个 View Controller 上设置了一个导航控件,我将其命名为 userOview 和标识符membersArea。每当我尝试使用prepareforsegue时,我都会收到以下错误
Could not cast value of type 'xxxxxxxx.DjInformation' (0x115da8) to 'UINavigationController' (0x3ad405e0).
我的应用程序代理看起来像这样
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var centerContainer: MMDrawerController?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()
let isLoggedIn:Int = prefs.integerForKey("ISLOGGEDIN") as Int
if (isLoggedIn == 1){
var rootViewController = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var centerViewController = mainStoryboard.instantiateViewControllerWithIdentifier("memberArea") as! userOverview
var leftViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LeftSideViewController") as! LeftSideViewController
var rightViewController = mainStoryboard.instantiateViewControllerWithIdentifier("RightSideViewController")as! RightSideViewController
var leftSideNav = UINavigationController(rootViewController: leftViewController)
var centerNav = UINavigationController(rootViewController: centerViewController)
var rightNav = UINavigationController(rootViewController: rightViewController)
centerContainer = MMDrawerController(centerViewController: centerNav, leftDrawerViewController: leftSideNav,rightDrawerViewController:rightNav)
centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView;
centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView;
window!.rootViewController = centerContainer
window!.makeKeyAndVisible()
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}
// MARK: - Core Data stack
lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "bfd.Be_Fit_Donate" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1] as! NSURL
}()
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = NSBundle.mainBundle().URLForResource("Be_Fit_Donate", withExtension: "momd")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("Be_Fit_Donate.sqlite")
var error: NSError? = nil
var failureReason = "There was an error creating or loading the application's saved data."
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
coordinator = nil
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}
return coordinator
}()
lazy var managedObjectContext: NSManagedObjectContext? = {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
let coordinator = self.persistentStoreCoordinator
if coordinator == nil {
return nil
}
var managedObjectContext = NSManagedObjectContext()
managedObjectContext.persistentStoreCoordinator = coordinator
return managedObjectContext
}()
// MARK: - Core Data Saving support
func saveContext () {
if let moc = self.managedObjectContext {
var error: NSError? = nil
if moc.hasChanges && !moc.save(&error) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(error), \(error!.userInfo)")
abort()
}
}
}
}
我尝试发送prepareforsegue的 View Controller 如下
import UIKit
import AVFoundation
import AVKit
import Foundation
import Social
public var AudioPlayer = AVPlayer()
public var SelectedSongNumber = Int()
public var TrackName = String()
public var TrackImage = String()
public var TrackDJ = String()
class MusicListTableViewController: UITableViewController, AVAudioPlayerDelegate{
@IBOutlet weak var playerView: UIView!
@IBOutlet weak var songName: UILabel!
@IBOutlet weak var playButton: UIButton!
@IBOutlet weak var trackDjName: UILabel!
@IBOutlet weak var imageArtwork: UIImageView!
var trackName = [String]()
var artistLabel = [String]()
var trackUrl = [String]()
var artWork = [String]()
var tags = [String]()
var artistId = [String]()
var djInfo = ""
@IBAction func facebookButton(sender: UIButton) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
var facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookSheet.setInitialText("Share on Facebook")
self.presentViewController(facebookSheet, animated: true, completion: nil)
} else {
var alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
@IBAction func tritterButton(sender: UIButton) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter){
var twitterSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
twitterSheet.setInitialText("Share on Twitter")
self.presentViewController(twitterSheet, animated: true, completion: nil)
} else {
var alert = UIAlertController(title: "Accounts", message: "Please login to a Twitter account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
@IBAction func myPlayList(sender: UIButton) {
var centerViewController = self.storyboard?.instantiateViewControllerWithIdentifier("myMusicList") as! myMusicList
var centerNavController = UINavigationController(rootViewController: centerViewController)
var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.centerContainer!.centerViewController = centerNavController
appDelegate.centerContainer!.toggleDrawerSide(MMDrawerSide.Right, animated: true, completion: nil)
}
@IBAction func favoriteButton(sender: UIButton) {
var favSong = trackName[SelectedSongNumber]
var alertView:UIAlertView = UIAlertView()
alertView.title = "Nummer Toegevoegd"
alertView.message = "Het nummer \(favSong) is nu toegevoegd aan uw favorieten muziek lijst"
alertView.delegate = self
alertView.addButtonWithTitle("OK")
alertView.show()
}
@IBAction func djInformation(sender: UIButton) {
var centerViewController = self.storyboard?.instantiateViewControllerWithIdentifier("djInformation") as! DjInformation
var centerNavController = UINavigationController(rootViewController: centerViewController)
var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.centerContainer!.centerViewController = centerNavController
appDelegate.centerContainer!.toggleDrawerSide(MMDrawerSide.Right, animated: true, completion: nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var artist_label = artistLabel[SelectedSongNumber]
if (segue.identifier == "djInformation" ){
var detailVC = segue.destinationViewController as! UINavigationController
let targetController = detailVC.topViewController as! DjInformation
targetController.djInfo = "hello"
}
}
func getMusicListJSON(){
let urlString = "http://xxxxxxxxxx"
let urlEncodedString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
let url = NSURL( string: urlEncodedString!)
var task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, innerError) in
let json = JSON(data: data)
let musicArray = json.arrayValue
//NSLog("\(json)")
dispatch_async(dispatch_get_main_queue(), {
for musiclist in musicArray
{
let track_name = musiclist["track_name"].stringValue
let artist = musiclist["artist"].stringValue
let track_url = musiclist["track_url"].stringValue
let art_work = musiclist["artwork"].stringValue
let track_tags = musiclist["tags"].stringValue
let artist_id = musiclist["artist_id"].stringValue
//println( "track_name: \(track_name) artist: \(artist) track_url: \(track_url) artwork: \(art_work) track_tags: \(track_tags) artist_id: \(artist_id)" )
self.trackName.append(track_name)
self.artistLabel.append(artist)
self.trackUrl.append(track_url)
self.artWork.append(art_work)
self.tags.append(track_tags)
self.artistId.append(artist_id)
}
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
return
})
})
}
task.resume()
}
override func viewDidLoad() {
super.viewDidLoad()
getMusicListJSON()
playButton.addTarget(self, action: "playButtonTapped:", forControlEvents: .TouchUpInside)
playerView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height * 0.7)
playButton.hidden = true
var error: NSError?
var success = AVAudioSession.sharedInstance().setCategory(
AVAudioSessionCategoryPlayAndRecord,withOptions: .DefaultToSpeaker, error: &error)
if !success{
NSLog("Failed to set audio session category, Error: \(error)")
}
}
func playButtonTapped(sender: AnyObject){
// set play image to pause wehen video is paused and also back
if AudioPlayer.rate == 0
{
AudioPlayer.play()
playButton.setImage(UIImage(named:"pause"), forState: UIControlState.Normal)
} else {
AudioPlayer.pause()
playButton.setImage(UIImage(named: "play"), forState: UIControlState.Normal)
}
}
@IBAction func slideOutMenu(sender: AnyObject) {
var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.centerContainer!.toggleDrawerSide(MMDrawerSide.Left, animated: true, completion: nil)
}
@IBAction func musicMenu(sender: AnyObject) {
var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.centerContainer!.toggleDrawerSide(MMDrawerSide.Right, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return trackName.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("playerCell", forIndexPath: indexPath) as! playerTableViewCell
// Configure the cell...
cell.artistName.text = trackName[indexPath.row]
cell.trackName.text = artistLabel[indexPath.row]
return cell
}
// set the song to play according to the table row selected. Also set the name and artist.
func playSong() {
var playnumber = trackUrl[SelectedSongNumber]
var TrackName = trackName[SelectedSongNumber]
var TrackImage = artWork[SelectedSongNumber]
var TrackDJ = artistLabel[SelectedSongNumber]
var DjId = artistId[SelectedSongNumber]
AudioPlayer = AVPlayer(URL: NSURL(string: playnumber))
AudioPlayer.play()
songName.text = TrackName
trackDjName.text = TrackDJ
load_artwork(TrackImage)
playButton.hidden = false
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
SelectedSongNumber = indexPath.row
playSong()
}
// set the song artwork to display in the player for the current playing song.
func load_artwork(urlString: String){
var imgURL: NSURL = NSURL(string: urlString)!
let request: NSURLRequest = NSURLRequest(URL: imgURL)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!,error: NSError!) -> Void in
if error == nil {
self.imageArtwork.image = UIImage(data: data)
}
})
}
}
我认为这两个代码应该是问题的原因。但到目前为止,我找不到任何方法来传递任何变量,我将需要它来完成我的应用程序。我在这里做错了什么?
我真的可以在这里使用一些帮助来让它工作。也许我的导航 Controller 设置正确。作为第一个 View Controller 应该嵌入其中。但我不确定我是否正确地做到了这一点。
感谢您的帮助。
最佳答案
如果您知道应该做什么,我已经找到了非常简单的解决方案。当您使用 mmdrawer 并希望发送数据时,您可以创建一个prepareforsegue,但您还需要创建一个覆盖mmdrawer 的segue。我发现您使用以下内容就像使用prepareforsgue
@IBAction func djInformation(sender: UIButton) {
var artist_label = artistLabel[SelectedSongNumber]
var centerViewController = self.storyboard?.instantiateViewControllerWithIdentifier("djInformation") as! DjInformation
centerViewController.djINfo = "\(artist_label)"
var centerNavController = UINavigationController(rootViewController: centerViewController)
var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.centerContainer!.centerViewController = centerNavController
appDelegate.centerContainer!.toggleDrawerSide(MMDrawerSide.Right, animated: true, completion: nil)
}
所以基本上你在prepareforsegue中所做的事情你也可以在启动mmdrawercontroller的按钮中做。
希望这是有道理的并对其他人有帮助。我绝不是专业人士,我不确定这是否正确或者更像是黑客。但它又快又容易。
关于ios - 使用 mmdrawercontroller 快速准备segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32361510/
我一直在试图找出为什么这会给我一个错误: PREPARE test FROM 'SELECT t.blah FROM (SELECT ? AS blah) t;'; ERROR 1054 (42S22
我想了解 Go 中的 channel 。我读过默认情况下发送和接收 block ,直到发送方和接收方都准备好。但是我们如何确定发送方和接收方的准备情况。 例如在下面的代码中 package main
大部分的pytorch入门教程,都是使用torchvision里面的数据进行训练和测试。如果我们是自己的图片数据,又该怎么做呢? 1、我的数据 我在学习的时候,使用的是fashion-mnis
在我的 Storyboard中,controller1 有 natigationController 和 segues 到 controller 2。奇怪的是 Segue 工作正常但是 overrid
我正在尝试使用Openshift在线从我的仓库中放入一些代码。 我的构建编译正常,但是部署失败: error: update acceptor rejected nodejs-mongo-persis
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是无关紧要的,
我有一个每晚运行的存储过程。 它从链接服务器中提取一些数据并将其插入到运行 sql 代理作业的服务器上的表中。在运行 INSERT 语句之前,该过程检查链接服务器上的数据库是否联机 (STATE =
我对 PDO 准备好的语句比较陌生。 我忍不住觉得必须有一种更简单、更整洁的方法来执行以下操作:我无论如何都将所有内容加载到一个数组中,然后必须将整个内容重写为一组 ':blah '=>$found[
我正在准备一个 pandas 数据框,用于在 R 的 ggplot2 中绘制带有误差条的图,这需要计算列的统计数据。误差条需要最小值(平均值 - 标准偏差)和最大值(平均值+标准差)。我使用 grou
我的 prepareForSegue 方法没有将数据传递到目标 View Controller 。 var buttonsDictionary = [Int: UIButton]() func cre
需要帮助来完成这个简单的任务。该 sp 应该提供一个结果集,并将从 MS-Access-Database 报告目的中调用。 表名可变,但以数字 (lsid) 结尾。使用串联。max_prepared_
我正在为我工作的小型企业创建销售订单表单。我有一个表单连接到数据库以获取下拉菜单,然后连接到文本框以在需要时添加新数据。如果前面的部分中的所有数据框均已填写,还会出现另外四个部分。 链接到数据库的
以下代码: class Database { (...) public function query($query){ $this->stmt = $this->dbh
我正在开展一个学校项目,涉及一个具有数据库集成的网站。目前正致力于通过它向网站添加新内容(文本、标题、图像)。我已经可以通过网站向数据库添加新用户,但由于某种原因,相同的代码和逻辑不适用于内容。 我注
我如何mysqli::stmt->bind_param在mysql中被视为NULL的东西? 我目前正在使用 $stmt->bind_param('s', 'NULL'); 最佳答案 bind_para
我在此处运行准备 stmt 时遇到语法错误。我尝试手动执行 @c 中的查询并且它有效。不知道为什么 stmt 会给出这个错误。这是我正在使用的代码。 SET @i=24; SET @Bill_mont
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我想知道准备好的查询是否与未准备的查询一样安全。下面是两个示例,一个用于 SELECT,一个用于 UPDATE。第一行是未准备的查询,第二行是准备好的查询。 选择示例: $userDetails =
我是 ios 开发的新手,在我尝试做的事情上遇到了障碍。 我的方法中有这段代码,旨在将特定的 NSObject 从这个 View 传递到下一个 View ,但是它总是让我的应用程序崩溃。 -(void
自上次调用 segue 以来,我的 UIButton 类的 statValue 属性已更新,但 segue 仍发送旧的原始值。有没有办法刷新 prepare 函数(如下),以便它发送新值? overr
我是一名优秀的程序员,十分优秀!