Reputation: 345
I had an error with Xcode where I needed to fix the size class. After I did that, I went back to one of my table views, and it added white space above the first prototype cells in the tableview. How can I get rid of that space? I added this picture below to better describe what I mean.
https://www.dropbox.com/s/7ebxipb0r2jakav/TableViewProblem.png?dl=0
@IBOutlet var schoolTable: UITableView!
var namesArray = [String]()
var locationsArray = [String]()
var currentUser = PFUser.currentUser()
var theSchoolName: String = "None Selected"
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
namesArray.removeAll(keepCapacity: false)
locationsArray.removeAll(keepCapacity: false)
var query = PFQuery(className: "Schools")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = query.findObjects() as? [PFObject] {
for object in objects {
self.namesArray.append(object.valueForKey("schoolName") as! String)
self.locationsArray.append(object.valueForKey("schoolLocation") as! String)
self.schoolTable.reloadData()
}
}
} else {
println("Oops, it didn't work...")
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.namesArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:ChangeSchoolListTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! ChangeSchoolListTableViewCell
if namesArray.count > 0 {
cell.nameLabel.text = namesArray[indexPath.row]
cell.locationLabel.text = locationsArray[indexPath.row]
}
return cell
}
Upvotes: 1
Views: 905
Reputation: 29161
I've seen this a lot with Xcode storyboards.
The solution is to move the UITableView so its not the first view on the screen.
Space at the top of UITableViews
Upvotes: 1