UITableView cell Issue - ios

I am using a custom cell for my table view. I have a switch in my cell. When I toggle the switch for certain cells, my switch vanishes from random cells. This only happens if I give a target action to my switch. When I comment the addTarget code, the table view works fine. Can any one help please?
The snap shot of the custom cell is:
The code for my CellForRowAtIndexPath is:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = placesTableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ApproveCustomCell
cell.placeType.text = places[indexPath.row].type
cell.placeName.text = places[indexPath.row].name
cell.placePhone.text = places[indexPath.row].phone
cell.placeWebsite.text = places[indexPath.row].website
cell.placeAddress.text = places[indexPath.row].address
cell.switchOutlet.tag = indexPath.row
cell.switchOutlet.addTarget(self, action: #selector(self.approveRejectPlace(_:)), forControlEvents: .TouchUpInside)
if places[indexPath.row].status! == "Approved" {
cell.switchOutlet.on = true
}else {
cell.switchOutlet.on = false
}
return cell
}
UPDATE
This is my Approve/reject method:
func approveRejectPlace(sender: UISwitch!){
var url = "\(baseUrl)\(approveRejectUrl)"
if sender.on == true {
url += ("Approved/\(places[sender.tag].id))")
}else {
url += ("Rejected/\(places[sender.tag].id)")
}
print(self.places[sender.tag].name)
let parameters = ["key" : encryptedKey , "salt" : encryptedSalt]
self.view.lock()
dataProvider.hitWebservice(url, parameters: parameters) { (jsonArray) in
self.view.unlock()
if let results = jsonArray[0] as? NSDictionary {
if let result = results.objectForKey("result") as? Bool {
if result {
if sender.on {
self.places[sender.tag].status = "Approved"
}else {
self.places[sender.tag].status = "Rejected"
}
// self.placesTableView.reloadData()
}else {
invokeAlertMethod("Error", msgBody: "Failed to approve the place", delegate: self)
sender.on = false
}
}
}
}
}

Related

How to handle two table views in single view controller by using xibs as cell

I am trying to use the segment controller with 3 segments. If I click on first segment, I should get one tableview. When I click on second segment, I should get second tableview and for third segment I should get 3rd table view. Here I am using XIB's for tableview cell. I tried something but I am not getting any data in the table. The table is loading. But the cell is not loading. I am giving my code below. If any one helps me, would be very great. Thanks in advance.
var arr1 = ["1","2","3","4"]
var imagesarray = [UIImage(named: "11.png")!, UIImage(named: "22.png")!, UIImage(named: "33.png")!,UIImage(named: "11.png")!,UIImage(named: "22.png")!, UIImage(named: "33.png")!]
override func viewDidLoad() {
super.viewDidLoad()
view_track.isHidden = false
view_watch.isHidden = true
view_ebooks.isHidden = true
table_track.register(UINib(nibName: "ProgramMListenTableViewCell", bundle: nil), forCellReuseIdentifier: "ProgramMListenTableViewCell")
table_watch.register(UINib(nibName: "ProgramMWatchTableViewCell", bundle: nil), forCellReuseIdentifier: "ProgramMWatchTableViewCell")
table_watch.register(UINib(nibName: "ProgramEbooksTableViewCell", bundle: nil), forCellReuseIdentifier: "ProgramEbooksTableViewCell")
table_ebooks.delegate = self
table_ebooks.dataSource = self
table_track.delegate = self
table_track.dataSource = self
table_watch.delegate = self
table_watch.dataSource = self
self.navigationController?.setNavigationBarHidden(true, animated: false)
}
#IBAction func Segment(_ sender: Any) {
switch segment_program.selectedSegmentIndex
{
case 0:
view_track.isHidden = false
view_watch.isHidden = true
view_ebooks.isHidden = true
self.table_track.reloadData()
break
case 1:
view_track.isHidden = true
view_watch.isHidden = false
view_ebooks.isHidden = true
self.table_watch.reloadData()
name_program.text = "Videos"
break
case 2:
view_track.isHidden = true
view_watch.isHidden = true
view_ebooks.isHidden = false
self.table_ebooks.reloadData()
name_ebooks.text = "Ebooks"
break
default:
break
}
}
}
extension ProgramMListenViewController: UITableViewDataSource,UITableViewDelegate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == table_track{
return self.arr1.count
}else if tableView == table_watch{
return self.imagesarray.count
}else{
return self.arr1.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == table_track{
let cell = table_track.dequeueReusableCell(withIdentifier: "ProgramMListenTableViewCell") as! ProgramMListenTableViewCell
}else if tableView == table_watch{
let cell = table_watch.dequeueReusableCell(withIdentifier: "ProgramMWatchTableViewCell") as! ProgramMWatchTableViewCell
cell.img_watch.image = imagesarray[indexPath.row]
}else if tableView == table_ebooks{
let cell = table_ebooks.dequeueReusableCell(withIdentifier: "ProgramEbooksTableViewCell") as! ProgramEbooksTableViewCell
cell.image_ebooks.image = imagesarray[indexPath.row]
}
return UITableViewCell()
}
}
You have to return your cell, instead of always returning UITableViewCell()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == table_track{
let cell = table_track.dequeueReusableCell(withIdentifier: "ProgramMListenTableViewCell") as! ProgramMListenTableViewCell
return cell
}else if tableView == table_watch{
let cell = table_watch.dequeueReusableCell(withIdentifier: "ProgramMWatchTableViewCell") as! ProgramMWatchTableViewCell
cell.img_watch.image = imagesarray[indexPath.row]
return cell
}else if tableView == table_ebooks{
let cell = table_ebooks.dequeueReusableCell(withIdentifier: "ProgramEbooksTableViewCell") as! ProgramEbooksTableViewCell
cell.image_ebooks.image = imagesarray[indexPath.row]
return cell
}
return UITableViewCell()
}
As mentioned before you need to return the respective UITableViewCell, depending on the table in order for it to be shown. You should watch for errors in dequeueReusableCell(), thus I recommend the following implementation:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var returnCell = UITableViewCell()
if tableView == table_track{
guard let cell = table_track.dequeueReusableCell(withIdentifier: "ProgramMListenTableViewCell") as? ProgramMListenTableViewCell else {
print("Error getting cell as ProgramMListenTableViewCell")
return returnCell
}
/*Customize your cell*/
returnCell = cell
}else if tableView == table_watch{
guard let cell = table_watch.dequeueReusableCell(withIdentifier: "ProgramMListenTableViewCell") as? ProgramMWatchTableViewCell else {
print("Error getting cell as ProgramMWatchTableViewCell")
return returnCell
}
/*Customize your cell*/
cell.img_watch.image = imagesarray[indexPath.row]
returnCell = cell
}else if tableView == table_ebooks{
guard let cell = table_ebooks.dequeueReusableCell(withIdentifier: "ProgramMListenTableViewCell") as? ProgramEbooksTableViewCell else {
print("Error getting cell as ProgramEbooksTableViewCell")
return returnCell
}
cell.image_ebooks.image = imagesarray[indexPath.row]
returnCell = cell
}
return returnCell
}
This way you have a safe way of getting the correct type of your cell, editing it and returning it to the corresponding table.

In table view cell data was not loading in screen during it's launch?

In this i am having three sections in a table view in which first section will have addresses and radio buttons if i click on radio button it will active and the particular address will be posting depending on the address selection the third section needs to call the api and load the data in the second table view which is present in third section here the problem is during loading for first time when app launched in simulator it is not loading the third section cell data can any one help me how to reduce the error ?
here is the code for table view class
func numberOfSections(in tableView: UITableView) -> Int
{
if ((addressSelected == true || checkIsPaymentRadioSelect == true) && selected == false) {
return 3
}else {
return 2
}
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
if ((addressSelected == true || checkIsPaymentRadioSelect == true) && selected == false) {
if (section == 0) {
return "SHIPPING ADDRESS"
}
else if (section == 2) {
return "SHIPPING METHOD"
}
else {
return ""
}
}
else {
if (section == 0) {
return "SHIPPING ADDRESS"
}
else{
return ""
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
if (section == 0)
{
return shippingArray.count
}
else
{
return 1
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
if ((addressSelected == true || checkIsPaymentRadioSelect == true) && selected == false){
if (indexPath.section == 0){
return UITableViewAutomaticDimension
}
else if (indexPath.section == 1){
return 62
}
else {
print(height)
return CGFloat(height)
}
}
else{
if (indexPath.section == 0){
return UITableViewAutomaticDimension
}
else if (indexPath.section == 1){
return 62
}
else {
return 0
}
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0)
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AddressTableViewCell
tableDetails.isHidden = false
activityIndicator.stopAnimating()
let arr = shippingArray[indexPath.row]
cell.deleteButton.tag = indexPath.row
cell.nameLabel.text = arr["name"] as? String
cell.addressLabel.text = arr["address"]as? String
let mobilenumber : Any = arr["number"] as AnyObject
cell.mobileNumberLabel.text = "\(mobilenumber)"
cell.radioButton.tag = indexPath.row
cell.editButton.tag = indexPath.row
cell.deleteButton.tag = indexPath.row
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
cell.radioButton.addTarget(self, action: #selector(selectRadioButton(_:)), for: .touchUpInside)
cell.deleteButton.addTarget(self, action: #selector(deleteAction(button:)), for: .touchUpInside)
let checkIndex = self.checkIsRadioSelect.index(of: indexPath.row)
if(checkIndex != nil){
cell.radioButton.isSelected = true
cell.editButton.isHidden = false
cell.deleteButton.isHidden = false
}
else
{
cell.radioButton.isSelected = false
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
}
if (checkIsPaymentRadioSelect == true){
let defaultvalue = arr["default"] as! Int
if defaultvalue == 1 {
cell.radioButton.isSelected = true
cell.editButton.isHidden = false
cell.deleteButton.isHidden = false
addressSelected = true
tableDetails.tableFooterView?.isHidden = false
}
}
return cell
}
else if (indexPath.section == 1){
let cell = tableView.dequeueReusableCell(withIdentifier: "addresscell", for: indexPath) as! CreateNewAddressTableViewCell
cell.newAddressButton.addTarget(self, action: #selector(newAddressAction(_:)), for: .touchUpInside)
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "shippingmethodcell", for: indexPath) as! MethodTableViewCell
cell.delegate = self
cell.boolDelegate = self
cell.shippingTableView.reloadData()
if shippingRadio == true {
cell.select = shippingRadio
cell.boolSelected()
cell.shippingmethodURL()
cell.shippingTableView.reloadData()
}
else{
cell.select = methodRadio
cell.shippingTableView.reloadData()
}
return cell
}
}
in this cell class i had got the api data and is passed to table view as shown in the code now i need to call api during cell selection of address can anyone help me how to clear the error or any alternative for this
var chekIndex:IndexPath?
var arrayss = [String:Any]()
var keys = [String]()
let urlString = "http://www.json-generator.com/api/json/get/bVgbyVQGmq?indent=2"
var delegate: CheckoutDelegate?
var heightConstant: Int?
var name = [String]()
var totalCount = 0
var radioSelected:Bool?
var radioSelection: Bool?
var boolDelegate: BoolValidationDelegate?
var select:Bool?
override func awakeFromNib() {
super.awakeFromNib()
radioSelection = false
self.shippingmethodURL()
shippingTableView.delegate = self
shippingTableView.dataSource = self
shippingTableView.rowHeight = UITableViewAutomaticDimension
shippingTableView.estimatedRowHeight = shippingTableView.rowHeight
// Initialization code
}
func paymentRadioAction(button : KGRadioButton) {
_ = button.center
let centralPoint = button.superview?.convert(button.center, to:self.shippingTableView)
let indexPath = self.shippingTableView.indexPathForRow(at: centralPoint!)
if button.isSelected {
} else{
chekIndex = indexPath
radioSelection = true
self.shippingTableView.reloadData()
self.boolDelegate?.boolvalidation(bool: radioSelection!)
}
}
func shippingmethodURL() {
guard let url = URL(string: self.urlString) else {return}
URLSession.shared.dataTask(with: url, completionHandler: {(data, response, error) -> Void in
if let data = data, let jsonObj = (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)) as? [String:Any] {
self.arrayss = jsonObj
self.keys = Array(jsonObj.keys)
for value in jsonObj.values {
if let array = value as? [[String:Any]] {
for element in array {
if (element["name"] as? String) != nil {
self.totalCount += 1
}
}
}
}
DispatchQueue.main.async {
self.shippingTableView.reloadData()
let sectionHeight = self.arrayss.count * 31
let cellHeight = self.totalCount * 44
self.shippingHeightConstraint.constant = CGFloat(sectionHeight + cellHeight)
self.heightConstant = Int(self.shippingHeightConstraint.constant)
self.delegate?.heightConstant(int: self.heightConstant!)
}
}
}).resume()
}
func numberOfSections(in tableView: UITableView) -> Int {
return arrayss.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.keys[section]
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let key = self.keys[section]
let a :[Any] = arrayss[key] as! [Any]
return a.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "shippingCell", for: indexPath) as! ShippingMethodTableViewCell
let key = self.keys[indexPath.section]
var a :[Any] = arrayss[key] as! [Any]
var dictionary = a[indexPath.row] as! [String:Any]
let name = dictionary["name"]
let price = dictionary ["price"]
cell.methodLabel.text = name as? String
cell.priceLabel.text = price as? String
cell.radioButton.addTarget(self, action: #selector(paymentRadioAction(button:)), for: .touchUpInside)
if chekIndex == indexPath {
cell.radioButton.isSelected = true
} else {
cell.radioButton.isSelected = false
}
return cell
}
and the first time image loading is shown below
!enter image description here ]1
and if i select another radio button in first section it was working fine as expected and image is shown below

Only Single cell expands at a time in UITableViewCell in swift3

I am implementing an expandable and collapsable table cell on the click of a button in the custom table cell. I have tried the following code but it expands only single cell at a time. That is if I click a cell it expands but if I click on another cell it expands and the already expanded cell collapses.
var selectedIndexPath: IndexPath?
func configure(cell: MyProposalCustomCell, forRowAtIndexPath indexPath: IndexPath) {
let pool = myProposalsDetails[indexPath.row]
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
cell.proposalNumber.text = pool.proposalNumber
cell.pickUpLocation.text = pool.pickupLocation
cell.dropLocation.text = pool.dropLocation
cell.journeyType.text = pool.journeyType
cell.firstShiftOnwardTime.text = pool.firstPickupTime
cell.firstShiftReturnTime.text = pool.firstEndTime
if let numberOfInterests = pool.noOfInterest {
cell.numberOfInterest.text = String(numberOfInterests)
}
if let operatingDays = pool.operatingDays {
cell.daysOfOperation.attributedText = Utility.getProposedOperatingDays(operatingDays: operatingDays)
}
cell.expandCollapse.tag = indexPath.row
cell.expandCollapse.addTarget(self, action: #selector(expandTableCell(sender:)), for: .touchUpInside)
if selectedIndexPath == indexPath {
UIView.animate(withDuration: 0.3, animations: {
cell.backgroundColor = CustomColor.selectedBackground.color
cell.bottomView.backgroundColor = CustomColor.selectedBackground.color
cell.expandCollapse.setImage(UIImage(named: "collapse_arrow.png"), for: .normal)
if let proposedStartDate = pool.startDate {
let propStartDate = Date(timeIntervalSince1970: proposedStartDate)
cell.proposedStartDate.text = Utility.getFormattedDate(date: propStartDate)
cell.proposedStartDateTxt.text = NSLocalizedString("Proposed start date", comment: "")
}
cell.returnTime.alpha = 0.0
})
} else {
UIView.animate(withDuration: 0.3, animations: {
cell.backgroundColor = UIColor.white
cell.expandCollapse.setImage(UIImage(named: "down_arrow.png"), for: .normal)
cell.proposedStartDateTxt.text = NSLocalizedString("Journey type", comment: "")
cell.bottomView.backgroundColor = UIColor.white
cell.proposedStartDate.text = pool.journeyType
cell.returnTime.isHidden = false
})
}
}
This is the expandable button action:
func expandTableCell(sender: UIButton) {
let indexPath = IndexPath(row: sender.tag, section: 0)
if selectedIndexPath == indexPath {
selectedIndexPath = nil
} else {
let previousSelIndex = selectedIndexPath
selectedIndexPath = indexPath
if let previousSelectedIndexPath = previousSelIndex {
if tripStatus.tripType != .splitShift {
if let previousSelectedCell = myProposals.cellForRow(at: previousSelectedIndexPath) as? MyProposalCustomCell {
configure(cell: previousSelectedCell, forRowAtIndexPath: previousSelectedIndexPath)
}
} else {
if let previousSelectedCell = myProposals.cellForRow(at: previousSelectedIndexPath) as? MyProposalSplitShiftCell {
configureSplitShift(cell: previousSelectedCell, forRowAtIndexPath: previousSelectedIndexPath)
}
}
}
}
updateSelectedCell(indexPath: indexPath)
myProposals.beginUpdates()
myProposals.endUpdates()
}
func updateSelectedCell(indexPath: IndexPath) {
if tripStatus.tripType != .splitShift {
if let selectedCell = myProposals.cellForRow(at: indexPath) as? MyProposalCustomCell {
configure(cell: selectedCell, forRowAtIndexPath: indexPath)
}
} else {
if let selectedCell = myProposals.cellForRow(at: indexPath) as? MyProposalSplitShiftCell {
configureSplitShift(cell: selectedCell, forRowAtIndexPath: indexPath)
}
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let headingHeight: CGFloat = 128
let detailsHeight: CGFloat = 80
let splitShiftDetailsHeight: CGFloat = 215
switch tripStatus.tripType {
case .oneWayTrip, .roundTrip:
if selectedIndexPath != nil && indexPath.compare(selectedIndexPath! as IndexPath) == ComparisonResult.orderedSame {
return headingHeight + detailsHeight
}
return headingHeight
case .splitShift:
if selectedIndexPath != nil && indexPath.compare(selectedIndexPath! as IndexPath) == ComparisonResult.orderedSame {
return headingHeight + splitShiftDetailsHeight
}
return headingHeight
}
}
I want to get multiple cells to be expanded. How to achieve this?
This is very straight forward, instead of taking selectedIndexPath try to keep one variable in your custom UITableViewCell class something like,
class ExpandableCell: UITableViewCell {
var isExpanded: Bool = false
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
#IBAction func moreButtonTapped(_ sender: Any) {
}
}
And then try to toggle the isExpanded boolean flag, and try to perform your func updateSelectedCell(indexPath: IndexPath) {} action.

When i ckeck a checkbox all checkboxes are checked (Swift)

Hello i have a collection view in which i have a checkbox in every cell.
I use this checkbox https://github.com/zhouhao27/WOWCheckbox.
All cells have their checkbox but the problem as the title says is that when i tap on the checkbox all checkboxes are checked.
Actually when i tap the first all odds checkboxes (1-3-5-7-...) are checked and when i tap the second then all checkboxes are checked.
I connected the view to my cell file i change it to WOWCheckbox as the documentation says.
I didn't change anything else.
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Interest Cell", forIndexPath: indexPath) as! ThirdTabCell
cell.check1.tag = indexPath.row
cell.check1.addTarget(self, action: #selector(ThirdTab.follow(_:)), forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
func follow(sender:WOWCheckbox!) {
print("check")
}
When i use this code when i tap a checkbox it prints check only once.
I believe i somehow i have to declare which check i tap but i don't know how to use it.
// func follow(sender:WOWCheckbox!) {
// sender.tag//will get the which row you checked
//do logic based on tag
//}
//Create model
class checkList{
var item = ""
var checked = false
}
//Controller
class SampleViewController: ViewController,WOWCheckboxDelegate{
var List = [checkList]()
override func viewDidLoad() {
super.viewDidLoad()
for i in 1...10 {
let object = checkList()
object.item = i.description
object.checked = false
List.append = obj
}
_collectionview.reloadData()
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Interest Cell", forIndexPath: indexPath) as! ThirdTabCell
cell.check1.tag = indexPath.row
if List[indexPath.row].checked {
cell.check1.isChecked = true
}
else{
cell.check1.isChecked = false
}
return cell
}
//delegate function by WOWCheckbox
func didSelectCheckbox(checkbox : WOWCheckbox) {
if checkBox.tag == 0{
//first row
for i ...< List.count {
if i % 2 != 0 {
List[i].checked = true
}
else{
List[i].checked = false
}
collectionView.reloadData()
return
}
}
//second row
else if checkBox.tag == 1{
for obj in List {
obj.checked = true
}
collectionView.reloadData()
return
}
else {
if list[checkbox.tag].isChecked {
checkBox.isChecked = false
list[checkbox.tag].checked = false
}
else{
list[checkbox.tag].checked = true
checkBox.isChecked = true
}
}
}
}
i didn't tested please check the code and change according to your requirement

Transferring UITableView Section to Another TableView

I am currently set up to transfer section 1 of my tableview to another tableView. This is done by moving the didSelectRow: rows. However, the issue is that when I attempt to move the section when every row is selected (and there is nothing in section 0) it crashes with an index is beyond bounds error.
I am using a boilerPlate code for my sectionHeaders due to section 1 header changing back to section 0 header when all items selected in section 1. I believe this is what is causing the index to be out of bounds error, but am not sure how to correct it.
My sections are set up as:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
let numberOfSections = frc.sections?.count
return numberOfSections!
}
//Table Section Headers
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
let sectionHeader = "Items Needed - #\(frc.sections![section].numberOfObjects)"
let sectionHeader1 = "Items in Cart - #\(frc.sections![section].numberOfObjects)"
if (frc.sections!.count > 0) {
let sectionInfo = frc.sections![section]
if (sectionInfo.name == "0") {
return sectionHeader
} else {
return sectionHeader1
}
} else {
return nil
}
}
with my didSelectRow and cells as:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SLTableViewCell
//assign delegate
cell.delegate = self
let items = frc.objectAtIndexPath(indexPath) as! List
cell.backgroundColor = UIColor.clearColor()
cell.tintColor = UIColor.grayColor()
cell.cellLabel.text = "\(items.slitem!) - Qty: \(items.slqty!)"
cell.cellLabel.font = UIFont.systemFontOfSize(25)
moveToPL.hidden = true
if (items.slcross == true) {
cell.accessoryType = .Checkmark
cell.cellLabel.textColor = UIColor.grayColor()
cell.cellLabel.font = UIFont.systemFontOfSize(20)
self.tableView.rowHeight = 50
moveToPL.hidden = false
} else {
cell.accessoryType = .None
cell.cellLabel.textColor = UIColor.blackColor()
cell.cellLabel.font = UIFont.systemFontOfSize(25)
self.tableView.rowHeight = 60
moveToPL.hidden = true
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let items = frc.objectAtIndexPath(indexPath) as! List
if (items.slcross == true) {
items.slcross = false
} else {
items.slcross = true
}
tableView.reloadData()
}
Is this my issue or is something else causing this?
Edit:
I tried changing my function in charge of moving items from this:
#IBAction func moveToPantry(sender: AnyObject) {
let sectionInfo = self.frc.sections![1]
let objectsToAppend = sectionInfo.objects as! [List]
for item in objectsToAppend {
item.slist = true
item.slcross = false
item.plist = false
item.slitem = item.pitem
item.slqty = item.pqty
item.sldesc = item.pdesc
item.slprice = item.pprice
item.slminqty = item.pminstepperlabel
}
}
to:
#IBAction func moveToSL(sender: AnyObject) {
if (frc.sections!.count > 0) {
let sectionInfo = self.frc.sections![1]
if (sectionInfo.name == "0") {
let objectsToAppend = sectionInfo.objects as! [List]
for item in objectsToAppend {
item.slist = true
item.slcross = false
item.plist = false
item.slitem = item.pitem
item.slqty = item.pqty
item.sldesc = item.pdesc
item.slprice = item.pprice
item.slminqty = item.pminstepperlabel
}
}
}
}
It is still throwing the error. It will move all the objects as long as section 0 isn't empty. Any more help in figuring this out would be appreciated! Thanks in advance.

Resources