I'm using tableview. Sometimes my datas getting error, because it is empty data. When I get empty data, I want to return 1 or more cell and show empty data information texts like "No data available!".

Code :

```
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var a:Int = 0

        if segmentControl.selectedIndex == 0 {
            a = 8
            return a
        }else if segmentControl.selectedIndex == 1{
            a = 4
            return a
        }else if segmentControl.selectedIndex == 2{
            a =  2
            return a
        }else if segmentControl.selectedIndex == 3{
            a = 1
            return a
        }

    return a
}

```

After then 0, all datas are empty. I'm trying to return cell and I'm using this code in `cellForRowAtIndexPath` :

```
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("knockoutsCell", forIndexPath: indexPath) as! KnockoutsTableViewCell

    let item = knockoutsTableArray[indexPath.row]
    if knockoutsTableArray.count == 0{
        cell.dateLabel.text = "Date"
        cell.homeImage.image = UIImage(named: "imagePic.png")
        cell.homeLabel.text = "Empty data!"

    }else{
    if item.playing == true{
        cell.dateLabel.text = item.date
        cell.homeImage.image = UIImage(named: "\(item.homeName)")
    }
    }

    return cell
}

```

**I found the solution and did it thanks to Sethmr. Here is my working code :**

```
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    if knockoutsTableArray.count != 0 {
        return knockoutsTableArray.count
    } else{
        if segmentControl.selectedIndex == 0{
            return 8
        }else if segmentControl.selectedIndex == 1{
            return 4
        }else if segmentControl.selectedIndex == 2{
            return 2
        }else{
            return 1
        }
    }
}

```

Also I moved the `item` value in `cellForRowAtIndexPath` from the top and It worked. I called the item when It's not empty.

```
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("knockoutsCell", forIndexPath: indexPath) as! KnockoutsTableViewCell

    if knockoutsTableArray.count == 0{
        cell.dateLabel.text = "Date"
        cell.homeImage.image = UIImage(named: "imagePic.png")
        cell.homeLabel.text = "Empty data!"

    }else{
    let item = knockoutsTableArray[indexPath.row]
    if item.playing == true{
        cell.dateLabel.text = item.date
        cell.homeImage.image = UIImage(named: "\(item.homeName)")
    }
    }

    return cell
}

```