回答
是可以將一個控制器導航到另一個使用屬性的控制器...
例如,
// 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];
}
犯錯,這是推視圖控制器點擊一個未知的UIView,並將圖像設置爲第二個控制器。我想OP是問如何推一個新的控制器的水龍頭'UIImage' – GoodSp33d
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 ..
}
雅則可以使用
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;
}
}
檢查更新的答案 –
爲了您的問題,我嘗試了下面的解決方案。並且它工作正常。
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
}
「imageviewNavigation」應該是我的圖像插座的名稱權? –
是的。那就是imageView插座。無論你想要設置你的圖像視圖名稱,只要給這裏。只要我設置圖像視圖名稱爲imageviewNavigation.That就是這樣。 – user3182143
好的,謝謝,現在我點擊Ctrl並從故事板中的畫板滑動到新的視圖控制器後,圖像似乎沒有讓我添加這個 –
- 1. 從ViewController導航到另一個ViewController
- 2. UIButton導航到另一個ViewController的WebView
- 3. 使用等待對話框導航到另一個ViewController
- 4. 如何使用按鈕從一個ViewController導航到另一個ViewController。 Swift 3(No StoryBoard)
- 5. 如何導航到另一個屏幕
- 6. 兩個導航Controllers-從最後導航到第一的ViewController
- 7. 一個ViewController轉到另一個ViewController
- 8. 如何將對象從一個ViewController傳遞到另一個ViewController
- 9. 如何導航到一個ViewController從UIView類的xib文件
- 10. 如何在第二個ViewController中從一個ViewController顯示UIImage?
- 11. 爲什麼導入一個ViewController會導致Xcode無法找到另一個ViewController?
- 12. UIAlertController按鈕點擊導航到一個導航控制器的第一個ViewController
- 13. 使用自定義Segue導航到另一個ViewController以編程方式
- 14. 從一個webview導航到另一個
- 15. 從AppDelegate導航到ViewController?
- 16. ViewController導航
- 17. Iphone導航到上一個/下一個viewController
- 18. 如何使用jQuery或JavaScript導航到另一個文件?
- 19. 如何使用onListItemClick導航到Android中的另一個屏幕
- 20. 如何使用QMouseEvent qt事件導航到另一個頁面
- 21. UIPage ViewController,我想從非uipage視圖控制器導航另一個第二viewcontroller
- 22. 如何導航一個xaml頁面到另一個頁面?
- 23. 如何在Caliburn.Micro中從一個ViewModel導航到另一個ViewModel?
- 24. 如何從一個屏幕導航到另一個屏幕
- 25. 如何從一個頁面導航到另一個離子
- 26. 我如何繪製一個圖像到另一個UIImage來創建一個UIImage
- 27. 如何在iphone sdk中的單個viewcontroller中從一個視圖導航到另一個視圖?
- 28. 移動到另一個ViewController
- 29. UIImagePickerController到另一個ViewController
- 30. 推送到另一個ViewController
你可以把上的UIImage的tapgesture然後搞定gesturen – jogshardik