mardi 18 juillet 2017

If statements when multiple are true

I am facing a problem by using if statements when there are multiple true

The first cell displays comments.

I have a textfield and when an @ is written I start a search within a second cell.

Now when clicked on the second cell, the usersSuggestion( who got shown) goes back to 0. ( removeAll())

I want to show cell1 when the usersSuggestion is 0.

But as I link users I need the @ sign in front of the names in order to go to their profile.

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


    if (commentTextField.text?.contains("@"))! {
        return usersSuggestion.count
    }

    if usersSuggestion.count == 0{
        return comments.count
    }
    if usersSuggestion.count == 1{
        return comments.count
    } else {
        return comments.count
    }
}

If clicked on a cell you can have this textfield for example

"Wow great day @Luca"

now there are multiple statements true

the text contains an @ sign and the usersSuggestion.count is 0.

But for as long as the text contains the @ nothing else will be considered.

Only if I delete the @ sign the cell1 shows again.

How can I work around this problem?

Aucun commentaire:

Enregistrer un commentaire