Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can fill two different tableview in one viewcontroller in swift 3

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if tableView == table1{
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! acntTableViewCell
        cell.account.text = account[indexPath.row].email
        return cell
    }
    else if tableView == table2 {
        let cell2 = tableView.dequeueReusableCell(withIdentifier: "cell2")
            as! popTableViewCell

        cell2.pop.text = pop[indexPath.row].answer
        return cell2
    }
}//its give me  error here Missing return  in function

I am going to fill two different tables in one viewcontroller. when I return cell it give me error Missing return in function where I am doing wrong can any one suggest me what's wrong with this code

like image 612
ahmed Avatar asked Jan 03 '18 19:01

ahmed


Video Answer


1 Answers

In the first place, you should compare tables using === (references), not ==.

This is one of the cases when an assertion failure is a good way to tell the compiler that no other way of the function exists e.g.:

if tableView === table1 {
    return ...
} else if tableView === table2 {
    return ...
} else {
    fatalError("Invalid table")
}

You can also use a switch:

switch tableView {
   case table1:
       return ...
   case table2:
       return ...
   default:
       fatalError("Invalid table")
}
like image 55
Sulthan Avatar answered Sep 26 '22 17:09

Sulthan