Swift Parse查询表

时间:2015-09-16 11:55:20

标签: ios swift parse-platform

我想通过PFQueryTableView和Cell从我的解析中导入一些数据。我在故事板上配置了一个tableview,并使用PFQueryTableViewController和PFQueryTableViewCell分配tableview和它的单元格。所以在我的tableview控制器上,我正在使用下面的代码,但它在super.init(className:myClassName)行上给出了错误消息“必须调用超类的指定初始化程序'PFQueryTableViewController'”

import UIKit
import Parse
import ParseUI

class parseTableView: PFQueryTableViewController {

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
    }

        init(className myClassName: String!) {
        super.init(className: myClassName)

        self.parseClassName = myColoumnName
        self.textKey = "myObjectKey"
        self.pullToRefreshEnabled = true
        self.paginationEnabled = false
    }
}

2 个答案:

答案 0 :(得分:0)

你必须更换

view.py

def add(request):
    template = loader.get_template('add.html')
    return HttpResponse(template.render())

def submit(request):

    Name = request.GET.get('name')
    Tb_name = request.GET.get('tb_name')
    Product_name = request.GET.get('product_name')
    Domain_name = request.GET.get('domain_name')
    ssh_ip = request.GET.get('ssh_ip')

    new= Testbeds(name=Name,tb_name=Tb_name, product_name=Product_name, domain_name=Domain_name, ssh_ip=ssh_ip)

    new.save()
    template = loader.get_template('add.html')
    return HttpResponse(template.render())




<!DOCTYPE html>
<html lang="en">
<head>



    <meta charset="UTF-8">
    <title>Add-New</title>

     <script src="static/js/script.js"></script>

    <script src="static/js/jquery.js"></script>
    <link rel="stylesheet" href="{{ STATIC_URL }} /static/css/style.css"/>
    <link rel="stylesheet" href="{{STATIC_URL}} /static/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="{{STATIC_URL}} /static/css/bootstrap-theme.min.css"/>

</head>
<body>
<header>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href=""> Testbeds </a>
        </div>
            <div>
            <ul class="nav navbar-nav">

             <li><a href="{% url 'index' %}"><span class="glyphicon glyphicon-dashboard"></span> Dashboard</a></li>

                    <li><a href="{% url 'add' %}"><span class="glyphicon glyphicon-plus"></span>
                        Add New</a></li>

            </ul>
        </div>
        </div>
        </nav>
</header> <!--header close-->
<br> <br> <br> <br>
<div class="container">
<form class="form-horizontal"  id="form" method="GET"  >{% csrf_token %}


  <div class="form-group">
      <h2 > Add new data:</h2>
      <br>
    <label class="control-label col-sm-2" >Name:</label>
    <div class="col-sm-3">
      <input type="text" name="name" class="form-control" id="name" placeholder="Enter name" >
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" >Tb_Name:</label>
    <div class="col-sm-3">
      <input type="text" name="tb_name" class="form-control" id="tb_name" placeholder="Enter Tb-name">
    </div>

  </div>
    <div class="form-group ">
             <label class="control-label col-sm-2" >Product_name:</label>
        <div class="col-sm-3">
            <input type="text" name="product_name" class="form-control" id="product_name" placeholder="Enter product name">
    </div>
    </div>

    <div class="form-group">
            <label class="control-label col-sm-2" >Domain_name:</label>
            <div class="col-sm-3">
                <input type="text" name="domain_name" class="form-control" id="domain_name" placeholder="Enter domain-name">
            </div>
  </div>
    <div class="form-group">
            <label class="control-label col-sm-2" >ssh_ip:</label>
        <div class="col-sm-3">
            <input type="text" name="ssh_ip" class="form-control" id="ssh_ip" placeholder="Enter ssh_ip">
        </div>
        </div>

        <br>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit"  id="submitTestbeds" class="btn btn-primary" value="submit" onclick=" return Testbeds" >
         <span class="glyphicon glyphicon-plus"></span> Submit
      </button>
    </div>
  </div>
</form>
 </div>


</body>
</html>

super.init(className: myClassName)

我检查了PFQueryTableViewController类的实现,我认为这是因为某些与将Swift桥接到Objective-C相关的缺陷。它与Swift中指定的初始化程序有关。因为上层init方法没有设置为Designated Initializer,而下层方法是。

答案 1 :(得分:0)

您需要覆盖queryForTable

  // Define the query that will provide the data for the table view
  override func queryForTable() -> PFQuery {
    var query = PFQuery(className: "myClassName")
    return query
  }

此外,在self.parseClassName = myColoumnName上,您应该提供一个类名而不是columnName。

此外,您需要覆盖init

  // Initialise the PFQueryTable tableview
  override init(style: UITableViewStyle, className: String!) {
    super.init(style: style, className: className)
  }

您可以找到更多详情here