- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个照片 View Controller ,可以在表格 View 中显示图像。我正在寻求帮助来连接到 fullsizeimageview ImageView Controller 。我不知道该怎么做。
import UIKit
import Parse
import ParseUI
class PhotosViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let arrSubCatData: NSMutableArray = [];
@IBOutlet weak var tblPhotos: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationItem.title = "Photos"
var tabBar : TabBarController = self.tabBarController as! TabBarController
println(tabBar.parkInfo)
self.tblPhotos.tableFooterView = UIView()
var query = PFQuery(className: "MultiImages")
query.whereKey("placeId", equalTo:tabBar.parkInfo?.valueForKey("objectId") as! String)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
self.arrSubCatData.addObjectsFromArray(objects!)
self.tblPhotos?.reloadData();
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("tableViewCell") as! UITableViewCell
if let file:PFFile = (self.arrSubCatData.objectAtIndex(indexPath.row).valueForKey("image") as? PFFile) {
file.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
var imgView : UIImageView = cell.contentView.viewWithTag(100) as! UIImageView
imgView.image = UIImage(data:imageData)
}
}
}
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("segueToInfo", sender: indexPath.row)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.arrSubCatData.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
/*override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showfullsizeimage" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let detailViewController = segue.destinationViewController as! PhotoFullSizeController
detailViewController.detailItem = objects[indexPath.row]
}
}
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
我新创建的全尺寸图像 Controller 是这样的,带有segue标识符“fullsizeimageview”
import UIKit
class PhotoFullSizeController: UIViewController {
@IBOutlet weak var fullImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
最佳答案
首先,您应该将 TapGesture
添加到 imgView
中。
您的cellForRowIndexPath
现在将如下:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("tableViewCell") as! UITableViewCell
if let file:PFFile = (self.arrSubCatData.objectAtIndex(indexPath.row).valueForKey("image") as? PFFile) {
file.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
var imgView : UIImageView = cell.contentView.viewWithTag(100) as! UIImageView
//Add Tap Gesture to the imgView
imgView.userInteractionEnabled = true;
let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped"))
imgView.addGestureRecognizer(tapRecognizer)
imgView.image = UIImage(data:imageData)
}
}
}
}
return cell
}
现在为 imageTapped
编写一个处理程序
//When image is tapped
func imageTapped()
{
println("image tapped")
self.performSegueWithIdentifier("fullsizeimageview", sender: self)
}
并且prepareForSegue
将如下所示:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "fullsizeimageview")
{
let destVC = (segue.destinationViewController as? PhotoFullSizeController)!
let indexPath = self.tblPhotos.indexPathForSelectedRow() //IndexPath for selected table row
if let file:PFFile = (self.arrSubCatData.objectAtIndex(indexPath!.row).valueForKey("image") as? PFFile) {
destVC.imageFile = file
}
}
}
在您的PhotoFullSizeController
Controller 中
class PhotoFullSizeController: UIViewController {
@IBOutlet weak var fullImageView: UIImageView!
var imageFile: PFFile!
override func viewDidLoad() {
super.viewDidLoad()
// Load image
self.imageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
//Set image in imageview
fullImageView.image = UIImage(data:imageData)
}
}
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
如果有任何问题请告诉我。希望这会有所帮助!
关于swift - 转到另一个 ImageView 以获取全尺寸图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893904/
我的网站使用 AmCharts,我想将其设为全尺寸。例如,我有以下代码: #chartdiv { width : 50%; height : 500px; float : left; } var
您需要使用edge或mozilla打开以下页面。 这是页面:codepen.io 这是我尝试过的: html{ max-height:1900px; max-width:2600px; } 因
我正在尝试通过以下代码使 html5 canvas 变为全尺寸。我知道还有其他使用 javascript 的方法,但是这有什么问题吗? Canvas_dot #m
如何达到outerPanel的全宽? private JPanel createLabelPanel() { final JToolTip tt = new JToolTip(
我的页面分为 3 个部分。 , 和 . 固定在顶部,大小为 109px,边框高 6px,因此 到顶部有 109 像素的边距。 我想要 扩展到 下面的整个页面和 那应该,如果没有可用于将其向下推的
我有一个网站需要在浏览器窗口中完全独立,即用户不必上下滚动即可查看网站的不同部分。太长而无法放入内容 Pane 的内容由 overflow:auto 处理,效果很好。 问题是,无论我怎么尝试,我仍然遇
我正在尝试设置一个网页,但由于我的元素的高度,我快疯了。特别是,我想要的布局是: 顶部有一个固定高度(例如 150 像素)和 100% 宽度的标题。 在标题下,我需要两列。左边的列有固定的宽度(例如
如何在 XAML 中将根布局的尺寸设置为 的 100% 宽度和高度?包含 Silverlight 应用程序的标记。 我试过指定 100%,但宽度和高度属性只采用单位文字(精确像素)。有没有办法让 S
ONLINE SAMPLE 我想让第一个 div layer1(红色 block )显示窗口的完整大小,可缩放。Layer2(蓝色 block )假设始终在 layer1 之下。但是,当我将窗口高度变
我不确定如何解释我到底想要什么(这也很难用谷歌搜索),但我想创建一个表格,每个单元格都有特定的宽度和高度(比如 40x40 像素) . 这个表格将比视口(viewport)大很多,所以它需要一些滚动,
我是一名优秀的程序员,十分优秀!