S
S
sergey ivanov2017-10-18 11:42:48
Swift
sergey ivanov, 2017-10-18 11:42:48

How to delist i.e. 2 row only 1 row in tablecell swift?

Good afternoon! Help me deal with the question: after the calculation, the HARD result appeared and 2 rows were displayed: Expert Hard and Cartridge Hard, I need to display only 1 row? for example, I chose new filter and Easy fit UTS the result was like in the 2nd screenshot, that is, from 2 row there should be 1 row - the result and switch to detailview? what function should I use?
Here is the code, is it true?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView. dequeueReusableCell(withIdentifier: "Cell")!
let producttype = ProductTypeControl.selectedSegmentIndex
let productlevel = ProductLevelControl.selectedSegmentIndex
if producttype ==0 && productlevel == 1 {
cell.imageProduct?.image = UIImage(named:ExpertHARD[indexPath.row])
cell.nameProduct?.text = ExpertHARD[indexPath.row]
}
else producttype == 1 && productlevel == 2 {
cell.imageProduct?.image = UIImage(named:CartridgeHARD[indexPath.row])
cell.nameProduct?.text = CartridgeHARD[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard indexPath.row == 1 else { return }
let vc = UIViewController()
navigationController ? .pushViewController(vc, animated: true)
}
59e713ba0fcfc550842130.png59e713c3882e0681688620.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Cherny, 2017-10-18
@freeg0r

the presence of logic in the methods of UI objects is not good. You must have some kind of array with data (products), which is the source for filling the table. Switching filters (segment controllers in your case) should change the objects in that array and reload the table. And the cellForRowAt indexPath method will only retrieve data from the array and fill in the cells, as well as the number of cells should come from the number of objects in the array with data (products). Once again, filtering occurs outside the table methods, you select from the list of all products only products that match the filters, put them in an array from which the table takes data by indexPath.row (cell index corresponding to the product index in the array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question