Я создаю приложение, которое выполняет поиск через UITableView. Когда пользователь выбирает первую опцию в поиске, он печатает первую опцию в UITableView, а не в списке результатов. Как я могу сделать так, чтобы при выборе строки это имя, а не первая строка в большом массиве?
Я провел исследование, Googled и YouTubed эту проблему, и мне не удалосьвыяснить.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (indexPath.section == 0) {
if (indexPath.row == 0) {
print("Amazon")
accountToTransfer = "Amazon"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
print("BMO Harris Bank")
accountToTransfer = "BMO Harris Bank"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Bitmoji")
accountToTransfer = "Bitmoji"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Bleacher Report")
accountToTransfer = "Bleacher Report"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 2) {
if (indexPath.row == 0) {
print("CBS Sports")
accountToTransfer = "CBS Sports"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Capital One")
accountToTransfer = "Capital One"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Chase Bank")
accountToTransfer = "Chase Bank"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Chick-Fil-A")
accountToTransfer = "Chick-Fil-A"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Costco")
accountToTransfer = "Costco"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 5) {
print("Craigslist")
accountToTransfer = "Craigslist"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 6) {
print("Credit Karma")
accountToTransfer = "Credit Karma"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 3) {
if (indexPath.row == 0) {
print("Delta")
accountToTransfer = "Delta"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Discord")
accountToTransfer = "Discord"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Discovery GO")
accountToTransfer = "Discovery"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Domino's Pizza")
accountToTransfer = "Domino's Pizza"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Door-Dash")
accountToTransfer = "Door-Dash"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 5) {
print("Dropbox")
accountToTransfer = "Dropbox"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 4) {
if (indexPath.row == 0) {
print("ESPN")
accountToTransfer = "ESPN"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Ebates")
accountToTransfer = "Ebates"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Ebay")
accountToTransfer = "Ebay"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Emirates")
accountToTransfer = "Emirates"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Evernote")
accountToTransfer = "Evernote"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 5) {
if (indexPath.row == 0) {
print("FOX Sports GO")
accountToTransfer = "FOX Sports GO"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Facebook")
accountToTransfer = "Facebook"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Fifth Third Bank")
accountToTransfer = "Fifth Third Bank"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Fitbit")
accountToTransfer = "Fitbit"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Fiverr")
accountToTransfer = "Fiverr"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 5) {
print("Flickr")
accountToTransfer = "Flickr"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 6) {
print("Flipboard")
accountToTransfer = "Flipboard"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 6) {
if (indexPath.row == 0) {
print("GameChanger")
accountToTransfer = "Gamechanger"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("GoodReads")
accountToTransfer = "GoodReads"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Google")
accountToTransfer = "Google"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("GroupMe")
accountToTransfer = "GroupMe"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Groupon")
accountToTransfer = "Groupn"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 7) {
if (indexPath.row == 0) {
print("HBO Now")
accountToTransfer = "HBO Now"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Houseparty")
accountToTransfer = "HouseParty"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Hulu")
accountToTransfer = "Hulu"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 8) {
if (indexPath.row == 0) {
print("Instagram")
accountToTransfer = "Instagram"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 9) {
if (indexPath.row == 0) {
print("Khols")
accountToTransfer = "Khols"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 10) {
if (indexPath.row == 0) {
print("LetGo")
accountToTransfer = "LetGo"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Linkden")
accountToTransfer = "Linkden"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("LockIt")
accountToTransfer = "LockIt"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Luftansa")
accountToTransfer = "Luftansa"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 11) {
if (indexPath.row == 0) {
print("MLB")
accountToTransfer = "MLB"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Match")
accountToTransfer = "Match"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("McDonalds")
accountToTransfer = "McDonalds"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Microsoft")
accountToTransfer = "Microsoft"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 12) {
if (indexPath.row == 0) {
print("NBC Sports")
accountToTransfer = "NBC Sports"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("NFL")
accountToTransfer = "NFL"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("NHL")
accountToTransfer = "NHL"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Netflix")
accountToTransfer = "Netflix"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 13) {
if (indexPath.row == 0) {
print("OfferUp")
accountToTransfer = "OfferUp"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Outlook")
accountToTransfer = "Outlook"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 14) {
if (indexPath.row == 0) {
print("PNC Bank")
accountToTransfer = "PNC Bank"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Pandora")
accountToTransfer = "Pandora"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("PayPal")
accountToTransfer = "PayPal"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("PhotoMath")
accountToTransfer = "PhotoMath"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Pinterest")
accountToTransfer = "Pinterest"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 5) {
print("Powerschool")
accountToTransfer = "Powerschool"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 15) {
if (indexPath.row == 0) {
print("Quora")
accountToTransfer = "Quora"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 16) {
if (indexPath.row == 0) {
print("Reddit")
accountToTransfer = "Reddit"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Redfin")
accountToTransfer = "Redfin"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Remind")
accountToTransfer = "Remind"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Roku")
accountToTransfer = "Roku"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 17) {
if (indexPath.row == 0) {
print("Sam's Club")
accountToTransfer = "Sam's Club"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Skype")
accountToTransfer = "Skype"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Slack")
accountToTransfer = "Slack"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Snapchat")
accountToTransfer = "Snapchat"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Southwest")
accountToTransfer = "Southwest"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 5) {
print("Spirit")
accountToTransfer = "Spirit"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 6) {
print("Spotify")
accountToTransfer = "Spotify"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 7) {
print("Starbucks")
accountToTransfer = "Starbucks"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 8) {
print("Strava")
accountToTransfer = "Strava"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 9) {
print("Sweatcoin")
accountToTransfer = "Sweatcoin"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 18) {
if (indexPath.row == 0) {
print("TCF Bank")
accountToTransfer = "TCF Bank"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("The Weather Channel")
accountToTransfer = "The Weather Channel"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Ticket Master")
accountToTransfer = "Ticket Master"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Tiktok")
accountToTransfer = "Tiktok"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Tinder")
accountToTransfer = "Tinder"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 5) {
print("Trivia Crack")
accountToTransfer = "Trivia Crack"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 6) {
print("Tumblr")
accountToTransfer = "Tumblr"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 7) {
print("TurboTax")
accountToTransfer = "TurboTax"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 8) {
print("Twitch")
accountToTransfer = "Twitch"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 9) {
print("Twitter")
accountToTransfer = "Twitter"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 19) {
if (indexPath.row == 0) {
print("US Bank")
accountToTransfer = "US Bank"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 20) {
if (indexPath.row == 0) {
print("VSCO")
accountToTransfer = "VSCO"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Verizon")
accountToTransfer = "Verizon"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Viber")
accountToTransfer = "Viber"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("Vimeo")
accountToTransfer = "Vimeo"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Vine")
accountToTransfer = "Vine"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 21) {
if (indexPath.row == 0) {
print("Walgreens")
accountToTransfer = "Walgreens"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Walmart")
accountToTransfer = "Walmart"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 2) {
print("Wells Fargo")
accountToTransfer = "Wells Fargo"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 3) {
print("WhatsApp")
accountToTransfer = "WhatsApp"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 4) {
print("Wish")
accountToTransfer = "Wish"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 22) {
if (indexPath.row == 0) {
print("Xbox")
accountToTransfer = "Xbox"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 23) {
if (indexPath.row == 0) {
print("Yahoo Sports")
accountToTransfer = "Yahoo Sports"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("Yelp")
accountToTransfer = "Yelp"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 24) {
if (indexPath.row == 0) {
print("Zillow")
accountToTransfer = "Zillow"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 25) {
if (indexPath.row == 0) {
print("iFunny")
accountToTransfer = "iFunny"
performSegue(withIdentifier: "Next", sender: self)
} else if (indexPath.row == 1) {
print("iHeartRadio")
accountToTransfer = "iHeartRadio"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 26) {
if (indexPath.row == 0) {
print("stackoverflow")
accountToTransfer = "stackoverflow"
performSegue(withIdentifier: "Next", sender: self)
}
} else if (indexPath.section == 27) {
if (indexPath.row == 0) {
print("theScore")
accountToTransfer = "theScore"
performSegue(withIdentifier: "Next", sender: self)
}
}
}
Когда первый результат нажимается (когда не выполняется поиск), он печатает Amazon. Я должен был искать «Reddit», и просматривал результаты поиска, при выборе он печатает первый вариант, который является Amazon, а не первый результат поиска, который должен быть Reddit.
Ошибки не отображаются. Когда я выбираю indexPath, он возвращает первый порядок массива. Я хочу массив UISearchResults.