将图像数组从tableview传递到collectionview

时间:2018-07-21 23:16:14

标签: arrays swift uicollectionview tableview

我必须查看控制器。首先是表格视图,其次是第二详细视图中的集合视图。我创建了一个由图像组成的数组。我希望单击单元格表,然后将一组图像传递到集合视图。我用数组数组定义了一个文件模型。我还为单元格表和单元格集合视图定义了两个控制器。

问题:我无法传递此阵列图像阵列。我确实使用prepare for segue将字符串数组传递给了详细的textview。沃尔克(Volk),非常感谢您的帮助。可以看看GitHub中的项目:https://github.com/ricardovaldes/hotelesWithIos9

此刻,当我单击表格单元格时,会得到一些不同数组的图片,无论我单击哪个单元格,都始终是相同的图片。

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<c:set var="context" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<head>
    <title>Login Page</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="<c:url value="${pageContext.request.contextPath}/resources/static/css/style.css" />" rel="stylesheet">


</head>
<body>

<h2>${pageContext.request.contextPath}</h2>

<br>
<div class="row">
    <div class="container">
        <div class="login-register-form-section">
            <ul class="nav nav-tabs" role="tablist">
                <li class="active"><a href="#login" data-toggle="tab">Login</a></li>
                <li><a href="#register" data-toggle="tab">Register</a></li>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane fade in active" id="login">
                    <form class="form-horizontal" method="post" action="">
                        <div class="form-group " >
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-user"></i></div>
                                <input type="text" name="login_email" class="form-control" placeholder="Username or email" required="required" value="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-key"></i></div>
                                <input type="password" name="login_password" class="form-control" placeholder="Password" required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <input type="checkbox" id="rememberMe">
                            <label for="rememberMe">Remember Me</label>
                            <a href="#" class="pull-right">Forgot password?</a>
                        </div>
                        <input type="submit" value="Login" class="btn btn-success btn-custom">

                    </form>
                </div>
                <div role="tabpanel" class="tab-pane fade" id="register">
                    <form class="form-horizontal" id="form">
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-user"></i></div>
                                <select type="text" id="sex" name="gender" class="form-control">
                                    <option>Male</option>
                                    <option>Female</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-male"></i></div>
                                <input type="text" id="register_username" class="form-control" placeholder="Username" required="required" value="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-envelope"></i></div>
                                <input type="email" id="register_email" class="form-control" placeholder="Email" required="required" value="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-skype"></i></div>
                                <input type="text" id="register_skype" class="form-control" placeholder="Skype name" required="required" value="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="input-group">
                                <div class="input-group-addon"><i class="fa fa-lock"></i></div>
                                <input type="password" id="register_password" class="form-control" placeholder="Password" required="required">
                            </div>
                        </div>
                        <input type="submit" id="submitbtn" value="Register" class="btn btn-success btn-custom">
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <center><h5 class="modal-title" id="exampleModalLabel">Your registration was successful! Please login!</h5></center>
            </div>
            <div class="modal-footer">
                <button type="button" id="confirm" class="btn btn-primary">Close</button>
            </div>
        </div>
    </div>
</div>




</body>
</html>

1 个答案:

答案 0 :(得分:0)

DetailVCViewController中,您正在创建Hotel的新对象,因此该对象与您在{{1}中的TableView cell中选择的对象不同}}。如下将ViewController对象替换为hotel,以便可以将数组从选定的array of String单元格索引传递到TabelView

DetailVCViewController

现在在class DetailVCViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { var array: [String] = [] var myDescription = "" .... } 中,如下更新ViewController以传递数组

prepare(for segue: