2015-10-18 4 views
0

Я хочу отправить данные в свой вид адаптера, где он должен помещать правильные данные в него. Я отправляю данные по переменной «exerciseName». В принтере правильно, но когда он достигает адресата, второй вид становится nil.Please помочьiOS Swift performSegueWithIdentifier для отправки данных

var workoutInfoData : WorkoutInfo! 
var RoundLabels = ["Round 1","Round 2","Round 3","Round 4","Round 5","Round 6","Round 7","Round 8","Round 9","Round 10","Round 11","Round 12"] 
var exerciseName:String = "" 

var roundPosition = [Int]() 
let numberOfExercises = 1 
var scrollerSize = 0 

override func viewDidLoad() { 
    super.viewDidLoad() 

    //self.workoutTitle.title! = workoutInfoData.workout_name 

    navigationItem.title = workoutInfoData.workout_name 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

@IBAction func workoutBack(sender: AnyObject) { 
self.dismissViewControllerAnimated(true, completion: {}); 
} 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return RoundLabels.count 

} 


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    var cell : RoundWorkoutCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as! RoundWorkoutCell 
    if(cell == nil) 
    { 
     cell = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil)[0] as! RoundWorkoutCell; 
    } 
    let exerviseName = RoundLabels[indexPath.row] 

    if(indexPath.row == 1){ 
    } 


    for countMe in 0..<self.numberOfExercises { 
     if(countMe<1){ 
      roundPosition.append(5) 
     }else{ 
      roundPosition.append(115+roundPosition[countMe-1]) 
     } 
     scrollerSize = 115+roundPosition[countMe] 
    } 

    cell.RoundExercise_Cell_ScrollView.contentSize = CGSizeMake(CGFloat(scrollerSize),115) 
    cell.RoundExercise_Cell_ScrollView.showsHorizontalScrollIndicator = true 
    cell.RoundExercise_Cell_ScrollView.indicatorStyle = .Default 


    for index in 0..<self.numberOfExercises { 
     var imageView : UIImageView 
     imageView = UIImageView(frame:CGRect(x:roundPosition[index],y: 5, width:110, height: 110)) 
     imageView.backgroundColor = UIColor.whiteColor() 
     cell.RoundExercise_Cell_ScrollView.addSubview(imageView) 

     let label1: UILabel = UILabel() 
     label1.frame = CGRect(x:roundPosition[index],y: 5, width:110, height: 20) 
     label1.textColor = UIColor(red:17/255.0, green: 22/255.0, blue: 40/255.0, alpha:1.0) 
     label1.textAlignment = NSTextAlignment.Center 
     label1.font = UIFont(name: "OpenSans-CondensedLight", size: 14) 
     label1.text = "Pushups" 
     cell.RoundExercise_Cell_ScrollView.addSubview(label1) 

     let frame1 = CGRect(x:roundPosition[index]+10,y:25, width:90, height: 90) 
     let button = UIButton(frame: frame1) 
     button.backgroundColor = UIColor.redColor() 
     button.setBackgroundImage(UIImage(named: "sit_thrust") as UIImage?, forState: .Normal) 
     button.setTitleColor(UIColor.blackColor(), forState: .Normal) 
     button.setTitle("air_sit_front_raise", forState: .Normal) 
     button.setTitleColor(UIColor(red:0/255,green:0/255,blue:0/255,alpha:0.0), forState: .Normal) 
     button.addTarget(self, action: "buttonClick:", forControlEvents: .TouchUpInside) 
     cell.RoundExercise_Cell_ScrollView.addSubview(button) 

     let label: UILabel = UILabel() 
     label.frame = CGRect(x:roundPosition[index],y: 115, width:110, height: 20) 
     label.font = UIFont(name: "OpenSans", size: 14) 
     label.textColor = UIColor.whiteColor() 
     label.textAlignment = NSTextAlignment.Center 
     label.text = "30sec" 
     cell.RoundExercise_Cell_ScrollView.addSubview(label) 

    } 



    cell.RoundExercise_Cell_Label.text = exerviseName 

    return cell as RoundWorkoutCell 
} 

func buttonClick(sender:AnyObject){ 
    exerciseName = String(sender.currentTitle) 
    //print(sender.currentTitle) 
    self.performSegueWithIdentifier("showExercise", sender:exerciseName) 
} 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == "showExercise" { 
     let vc = segue.destinationViewController as! ViewExerciseFromMenu 
     //vc.exerciseGet = UIImage(named: "sit_thrust")! 
     //vc.title = "SIT THRUSTS" 
     print(exerciseName) 
     vc.exerciseGet = exerciseName 

     navigationItem.title = "easy" 
    } 
} 

Точка зрения адаптера

@IBOutlet var imageView: UIImageView! 
@IBOutlet var musInvImageHolder: UIImageView! 

var exerciseGet: String = "" 

var image = UIImage() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view. 
    //var exerciseCurrent: String 
    print(exerciseGet) 
    switch(String(exerciseGet)){ 
    case "air_sit_front_raise": 
     self.title = "AIR SIT FRONT RAISE" 
     musInvImageHolder.image = UIImage(named: "mus_inv_20") 
     let url = NSBundle.mainBundle().URLForResource("air_sit_front_raise", withExtension: "gif")! 
     let imageData = NSData(contentsOfURL: url) 
     imageView.image = UIImage.animatedImageWithData(imageData!) 
     break; 
+0

Можете ли вы показать свой код «ViewExerciseFromMenu» и место, где вы пытаетесь получить доступ к «exerciseGet». – Abhinav

+0

Да, конечно, это –

+0

В качестве примера я приведу фрагмент кода. – Leviathlon

ответ

0

Вот исправление для него

@IBOutlet var roundExercisesTable: UITableView! 
var workoutInfoData : WorkoutInfo! 
var RoundLabels = ["Round 1","Round 2","Round 3","Round 4","Round 5","Round 6","Round 7","Round 8","Round 9","Round 10","Round 11","Round 12"] 
var exerciseName:String? = "" 
var myButtons: [Int : UIButton] = [:] 
var roundPosition = [Int]() 
let numberOfExercises = 1 
var scrollerSize = 0 


let exerciseInfo=ExercisesInfo() 
    override func viewDidLoad() 



{ 
     super.viewDidLoad() 

    //self.workoutTitle.title! = workoutInfoData.workout_name 

    navigationItem.title = workoutInfoData.workout_name 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

@IBAction func workoutBack(sender: AnyObject) { 
    self.dismissViewControllerAnimated(true, completion: {}); 
} 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return RoundLabels.count 

} 


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    var cell : RoundWorkoutCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as! RoundWorkoutCell 
    if(cell == nil) 
    { 
     cell = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil)[0] as! RoundWorkoutCell; 
    } 
    let exerviseName = RoundLabels[indexPath.row] 

    if(indexPath.row == 1){ 
    } 


    for countMe in 0..<self.numberOfExercises { 
     if(countMe<1){ 
      roundPosition.append(5) 
     }else{ 
      roundPosition.append(115+roundPosition[countMe-1]) 
     } 
     scrollerSize = 115+roundPosition[countMe] 
    } 

    cell.RoundExercise_Cell_ScrollView.contentSize = CGSizeMake(CGFloat(scrollerSize),115) 
    cell.RoundExercise_Cell_ScrollView.showsHorizontalScrollIndicator = true 
    cell.RoundExercise_Cell_ScrollView.indicatorStyle = .Default 


    for index in 0..<self.numberOfExercises { 
     var imageView : UIImageView 
     imageView = UIImageView(frame:CGRect(x:roundPosition[index],y: 5, width:110, height: 110)) 
     imageView.backgroundColor = UIColor.whiteColor() 
     cell.RoundExercise_Cell_ScrollView.addSubview(imageView) 

     let label1: UILabel = UILabel() 
     label1.frame = CGRect(x:roundPosition[index],y: 5, width:110, height: 20) 
     label1.textColor = UIColor(red:17/255.0, green: 22/255.0, blue: 40/255.0, alpha:1.0) 
     label1.textAlignment = NSTextAlignment.Center 
     label1.font = UIFont(name: "OpenSans-CondensedLight", size: 14) 
     label1.text = "Pushups" 
     cell.RoundExercise_Cell_ScrollView.addSubview(label1) 

     let frame1 = CGRect(x:roundPosition[index]+10,y:25, width:90, height: 90) 
     let button = UIButton(frame: frame1) 
     button.backgroundColor = UIColor.redColor() 
     button.setBackgroundImage(UIImage(named: "sit_thrust") as UIImage?, forState: .Normal) 
     button.setTitleColor(UIColor.blackColor(), forState: .Normal) 
     button.setTitle("air_sit_front_raise", forState: .Normal) 
     button.setTitleColor(UIColor(red:0/255,green:0/255,blue:0/255,alpha:0.0), forState: .Normal) 
     button.addTarget(self, action: "buttonClick:", forControlEvents: .TouchUpInside) 
     cell.RoundExercise_Cell_ScrollView.addSubview(button) 

     let label: UILabel = UILabel() 
     label.frame = CGRect(x:roundPosition[index],y: 115, width:110, height: 20) 
     label.font = UIFont(name: "OpenSans", size: 14) 
     label.textColor = UIColor.whiteColor() 
     label.textAlignment = NSTextAlignment.Center 
     label.text = "30sec" 
     cell.RoundExercise_Cell_ScrollView.addSubview(label) 

    } 



    cell.RoundExercise_Cell_Label.text = exerviseName 

    return cell as RoundWorkoutCell 
} 

func buttonClick(sender:AnyObject){ 
    exerciseName = sender.currentTitle 
    //print(sender.currentTitle) 
    self.performSegueWithIdentifier("showExercise", sender:exerciseName) 
} 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == "showExercise" { 
     let vc = segue.destinationViewController as! ViewExerciseFromMenu 
     //vc.exerciseGet = UIImage(named: "sit_thrust")! 
     //vc.title = "SIT THRUSTS" 
     print(exerciseName) 
     vc.exerciseGet = exerciseName! 
     navigationItem.title = exerciseInfo.hradnesExerciseDeterminer(exerciseName!) 
    } 
} 
Смежные вопросы