我想将数据发送到我的适配器视图,它应该将正确的数据发送到它。我通过" exerciseName"发送数据。变量。在打印中它是正确的但当它到达目的地时第二个视图它变为零。请帮助
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 :(得分: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!)
}
}