gpt4 book ai didi

xcode - 如何在 Xcode 中为我的 tableview 添加上边距?

转载 作者:IT王子 更新时间:2023-10-29 05:39:08 24 4
gpt4 key购买 nike

我正在尝试在 TableView 的第一个单元格的最顶部添加图像。我怎样才能让表格 View 有上边距?现在,图像只是与 tableview 重叠。我试图让表格 View 稍微下降一点。我不想让它变小或类似的东西。我只想在表格 View 的顶部添加一个按钮。

//
// usersVC.swift
// CaastRun
//
// Created by Computer on 5/23/15.
// Copyright (c) 2015 Caast. All rights reserved.
//

import UIKit

class usersVC: UIViewController, UITableViewDataSource, UITableViewDelegate {



@IBOutlet weak var resultsTable: UITableView!

var resultsNameArray = [String]()
var resultsUserNameArray = [String]()
var resultsImageFiles = [PFFile]()

override func viewDidLoad() {
super.viewDidLoad()
let theWidth = view.frame.size.width
let theHeight = view.frame.size.height
resultsTable.frame = CGRectMake(0, 0, theWidth, theHeight)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewDidAppear(animated: Bool) {


resultsNameArray.removeAll(keepCapacity: false)
resultsUserNameArray.removeAll(keepCapacity: false)
resultsImageFiles.removeAll(keepCapacity: false)

var query = PFUser.query()

query!.whereKey("username", notEqualTo: PFUser.currentUser()!.username!)

query!.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]?, error:NSError?) -> Void in

if error == nil {

for object in objects! {

self.resultsNameArray.append(object.objectForKey("profileName") as! String)
self.resultsImageFiles.append(object.objectForKey("photo") as! PFFile)
self.resultsUserNameArray.append(object.objectForKey("username") as! String)

self.resultsTable.reloadData()


}

}

}

}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return resultsNameArray.count

}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

return 64

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell:usersCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! usersCell

cell.profileLbl.text = self.resultsNameArray[indexPath.row]
cell.usernameLbl.text = self.resultsUserNameArray[indexPath.row]

var query = PFQuery(className: "follow")

query.whereKey("user", equalTo: PFUser.currentUser()!.username!)
query.whereKey("userToFollow", equalTo: cell.usernameLbl.text!)

query.countObjectsInBackgroundWithBlock {
(count:Int32, error:NSError?) -> Void in

if error == nil {

if count == 0 {

cell.followBtn.setTitle("Follow", forState: UIControlState.Normal)

} else {

cell.followBtn.setTitle("Following", forState: UIControlState.Normal)
}

}

}


self.resultsImageFiles[indexPath.row].getDataInBackgroundWithBlock {
(imageData:NSData?, error:NSError?) -> Void in

if error == nil {

let image = UIImage(data: imageData!)
cell.imgView.image = image

}

}

return cell

}

@IBOutlet weak var searchText: UITextField!


@IBAction func searchButton(sender: AnyObject) {
resultsNameArray.removeAll(keepCapacity: false)

resultsUserNameArray.removeAll(keepCapacity: false)

resultsImageFiles.removeAll(keepCapacity: false)

var query = PFUser.query()

query!.whereKey("username", notEqualTo: PFUser.currentUser()!.username!)

query!.whereKey("profileName", containsString: self.searchText.text)

query!.findObjectsInBackgroundWithBlock {

(objects:[AnyObject]?, error:NSError?) -> Void in

if error == nil {

for object in objects! {

self.resultsNameArray.append(object.objectForKey("profileName") as! String)

self.resultsImageFiles.append(object.objectForKey("photo") as! PFFile)

self.resultsUserNameArray.append(object.objectForKey("username") as! String)

self.resultsTable.reloadData()

}



}

}
}


}

最佳答案

我不确定我是否理解你的问题,如果你想在你的表格和 View 之间留出空白,试试这个:

swift 3

self.tableView.contentInset = UIEdgeInsets(top: 20,left: 0,bottom: 0,right: 0)

swift 2

self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);

关于xcode - 如何在 Xcode 中为我的 tableview 添加上边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30678391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com