I have a tableview inside a collection view cell. The tableview displays data which has been fetched. Although, the data fetched is sometimes nil and ends up looking like this:
In this case the company has no facebook name. At the moment I'm hard coding the tableview cell count:
var arrayForContactList : NSMutableArray = []
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
setupContactList()
}
func setupContactList() {
if let phoneNumber = selectedCompany.phoneNumber {
let dictionaryForContact = NSDictionary()
dictionaryForContact.setValue("Phone", forKey: "Title")
dictionaryForContact.setValue(phoneNumber, forKey: "Detail")
arrayForContactList.addObject(dictionaryForContact)
}
// And the rest...
self.tableView.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
as for displaying the data in the tableview:
let contactArray = ["Phone", "Website", "Email", "Twitter", "Facebook", "Instagram"]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellID") as! ContactCell
cell.contactLabel.text = arrayForContactList[indexPath.row].objectForKey("Title") as? String
cell.contactButton.setTitle(arrayForContactList[indexPath.row].objectForKey("Detail") as? String, forState: .Normal)
return cell
}
What I want to do reduce the size of the tableview by deleting cell(s) if the data = nil. Then, on top of that I want to decrease the size of the collectionview cell that the tableview sits in if cells from the tableview have been removed.