传递VC数据不能正常工作

时间:2016-02-02 16:10:50

标签: ios swift parse-platform

当用户点击我的应用程序中的图像时,我希望将它们发送到另一个视图控制器,以便为他们提供更多帖子详细信息,但我无法弄清楚如何将该图像从一个视图控制器传输到下一个视图控制器! 下面的代码,如果他们点击图像,应该将它们发送到详细的视图控制器 - 这是在else if语句中完成的。 override func prepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?){        if username!= PFUser.currentUser()?. username {             让profileVC:UserProfileViewController = segue.destinationViewController为! UserProfileViewController             profileVC.usernameString = username        } else if(segue.identifier ==“toPostDetail”){             var svc = segue.destinationViewController as! PostDetailsViewController             svc.toPass = //呼叫/传递图像       }  } 要检索我的数据库中的所有帖子,我使用以下代码,这运行完全正常,但我需要将postImage trasnfered转移到下一个视图控制器。 postsArray [indexPath.row] [“image”]。getDataInBackgroundWithBlock {(data,error) - >无效             如果let downloadedImage = UIImage(data:data!){                 postCellObj.postImage.image = downloadedImage                 postCellObj.postImage.layer.masksToBounds = true                 postCellObj.postImage.layer.cornerRadius = 5.0             }         } 那么我将在svc.toPass中放置什么才能将图像发送到其他视图控制器?由于这是一系列帖子,我是否必须使用didSelectRowAtIndexPath做一些事情,或者我做的是正确的事情吗?我也在使用Parse.com从我的数据库中获取信息。

1 个答案:

答案 0 :(得分:1)

你应该传递帖子而不是图像,所以它会像

postsArray[indexPath.row]

indexPath取决于你的方式。如果segue是由单元格选择触发的,那么您可以将indexPath存储在didSelectRowAtIndexPath中,或者当您触发segue时可以将indexPath作为sender传递,或者如果在segue过程中保留indexPathForSelectedRow,则可以使用#include <CGAL/Advancing_front_surface_reconstruction.h> #include <CGAL/compute_average_spacing.h> #include <CGAL/Delaunay_triangulation_3.h> #include <CGAL/Triangulation_data_structure_3.h> #include <CGAL/Polyhedron_3.h> #include <CGAL/Surface_mesh.h> #include <CGAL/IO/Polyhedron_iostream.h> #include <CGAL/Polygon_mesh_processing/refine.h> #include <CGAL/Polygon_mesh_processing/fair.h> typedef CGAL::Advancing_front_surface_reconstruction<> Reconstruction; typedef Reconstruction::Triangulation_3 Triangulation_3; typedef Reconstruction::Triangulation_data_structure_2 TDS_2; typedef Reconstruction::Outlier_range Outlier_range; typedef Reconstruction::Boundary_range Boundary_range; typedef Reconstruction::Vertex_on_boundary_range Vertex_on_boundary_range; typedef Reconstruction::Vertex_handle Vertex_handle; typedef CGAL::Polyhedron_3<CGALMesher::Kernel> Polyhedron; typedef CGAL::Surface_mesh<CGALMesher::Point> Mesh; typedef CGAL::cpp11::array<std::size_t,3> Facet; struct Construct { Mesh& mesh; template<typename PointIterator> Construct(Mesh& mesh, PointIterator b, PointIterator e) : mesh(mesh) { for (; b != e; ++b) { boost::graph_traits<Mesh>::vertex_descriptor v; v = add_vertex(mesh); mesh.point(v) = *b; } } Construct& operator=(const Facet f) { typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor; typedef boost::graph_traits<Mesh>::vertices_size_type size_type; mesh.add_face(vertex_descriptor(static_cast<size_type>(f[0])), vertex_descriptor(static_cast<size_type>(f[1])), vertex_descriptor(static_cast<size_type>(f[2]))); return *this; } Construct& operator*() { return *this; } Construct& operator++() { return *this; } Construct operator++(int) { return *this; } }; void CGALMesher::AdvancingFrontMesher(std::vector<Point>& points) { Mesh m; Construct construct(m,points.begin(),points.end()); CGAL::advancing_front_surface_reconstruction(points.begin(), points.end(), construct); std::ofstream mesh_off("mesh.off"); mesh_off << m; mesh_off.close(); std::ifstream input("mesh.off"); Polyhedron poly; if ( !input || !(input >> poly) || poly.empty() ) { std::cerr << "Not a valid off file." << std::endl; } input.close(); std::vector<Polyhedron::Facet_handle> new_facets; std::vector<Polyhedron::Vertex_handle> new_vertices; CGAL::Polygon_mesh_processing::refine(poly, faces(poly), std::back_inserter(new_facets), std::back_inserter(new_vertices), CGAL::Polygon_mesh_processing::parameters::density_control_factor(3)); std::ofstream refined_off("refined.off"); refined_off << poly; refined_off.close(); std::cout << "Refinement added " << new_vertices.size() << " vertices." << std::endl; }