2015-10-13 58 views

回答

-2

是可以將一個控制器導航到另一個使用屬性的控制器...

例如,

// second Controller.....(you pass image on this controller) 
#import <UIKit/UIKit.h> 
@interface NewScreen : UITableViewController 
{ 

} 
@property(strong,nonatomic)UIImage *yourImage; 
@end 


/// First Controller where you pass your image... 

- (IBAction)convertVideoButtonClicked:(id)sender 
{ 
    NewScreen *objNew=[self.storyboard instantiateViewControllerWithIdentifier:@"NewScreen"]; 
    objNew.yourImage=imageNamed; 
    [self.navigationController pushViewController:objNew animated:YES]; 
// NSURL *videoPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"part1" ofType:@"mov"]]; 
// [self convertVideoToMP4:videoPath]; 
} 
+0

犯錯,這是推視圖控制器點擊一個未知的UIView,並將圖像設置爲第二個控制器。我想OP是問如何推一個新的控制器的水龍頭'UIImage' – GoodSp33d

0
UIImageView *imageView=[[UIImageView alloc]init]; 
//add gesture recogniser 

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(navigate)]; 
tap.delegate=self; 
    [imageView addGestureRecognizer:tap]; 

//call method 
-(void)navigate{ 
    //call the navigation .. 
} 
3

雅則可以使用

var tap = UITapGestureRecognizer(target: self, action: Selector("imageCliecked")) 
yourimageView.addGestureRecognizer(tap) 
yourimageView.userInteractionEnabled = true // this is must dont forget to add 

方法是

func imageCliecked() 
{ 
println("Tapped on Image") 
// navigate to another 
self.performSegueWithIdentifier("yoursegueName", sender: self) 
} 

    override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?) 
    { 
    if segue.identifier == "yoursegueName" { 

    var destViewController: ViewController = segue.destinationViewController as ViewController 

    destViewController.img = imageView.image // pass your imageview 
    } 

    } 

另一個視圖控制器

class ViewController: UIViewController 
{ 

strong var img: UIImage! 

override function viewDidLoad() 
{ 
    if(self.img) 
    self.imageView.image = img; 
} 
} 
+0

檢查更新的答案 –

0

爲了您的問題,我嘗試了下面的解決方案。並且它工作正常。

override func viewDidLoad() 
    { 

    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    var tapGesture = UITapGestureRecognizer(target: self, action: "navigationFromImage:") 

    tapGesture.numberOfTapsRequired = 1 

    imageviewNavigation.userInteractionEnabled = true 

    imageviewNavigation.addGestureRecognizer(tapGesture) 

    } 

func navigationFromImage(sender: UIGestureRecognizer) 
{ 

    var secondViewController = storyboard?.instantiateViewControllerWithIdentifier("navigatingSecondViewController") as SecondViewController 

    secondViewController.globalImage = imageviewNavigation.image! 

    navigationController?.pushViewController(secondViewController, animated: true) 
       //OR 

    presentViewController(secondViewController, animated: true, completion: nil) 

} 

而且在故事板單擊所需的視圖控制器

 1.Go to or click show the Identity inspector 
    2.Click Identity 
    3.In StorybordId you must give "navigatingSecondViewController" or whatever you want. 
    4.Finally you must give same name in your storyboard?.instantiateViewControllerWithIdentifier("navigatingSecondViewController") 
在SecondViewController

var globalImage: UIImage = UIImage() 

    override func viewDidLoad() 
    { 

     super.viewDidLoad() 

     // Do any additional setup after loading the view. 

     imageAccess.image = globalImage 
    } 
+0

「imageviewNavigation」應該是我的圖像插座的名稱權? –

+0

是的。那就是imageView插座。無論你想要設置你的圖像視圖名稱,只要給這裏。只要我設置圖像視圖名稱爲imageviewNavigation.That就是這樣。 – user3182143

+0

好的,謝謝,現在我點擊Ctrl並從故事板中的畫板滑動到新的視圖控制器後,圖像似乎沒有讓我添加這個 –

相關問題