Я считаю, что проблема в том, что вы циклически просматриваете весь массив каждый раз, когда получаете запрос на ячейку.То, что вы, вероятно, хотите сделать, это получить number
для indexPath.row
и перебрать onlineUserArray
, чтобы найти статус.
Примерно так (я не знаю вашу точную структуру данных, ноэто должно быть вдоль правильных линий):
// inside cellForRowAt
cell = singleChatRoomsList.dequeueReusableCell(withIdentifier: "SingleRoomCellView") as! ChatRoomCellView
// just to make it easy to see what's going on in the debug console
print(indexPath)
let phone = numbers[indexPath.row]
for number in onlineUserArray
{
print(number)
if number.phone == phone
{
if number.status == 1
{
print("Matched")
cell.theLabel.backgroundColor = #colorLiteral(red: 0.08950354904, green: 0.807744801, blue: 0.07534810156, alpha: 1)
}
else if number.status == 0
{
cell.theLabel.backgroundColor = #colorLiteral(red: 0.6666666865, green: 0.6666666865, blue: 0.6666666865, alpha: 1)
}
else
{
cell.theLabel.backgroundColor = UIColor.clear
}
print("found a match, so break out of the loop")
break
}
}