-2
문자열이 0 일 때 레이블의 색상을 변경하고 싶습니다. < 빨간색. 내 첫 번째 문제는 int에서 문자열을 만드는 것입니다. 나는 이것을하려고 노력했다. 그러나 나는 일하지 않는 것처럼 보인다. 내가 뭘 잘못하고 있는지 모르겠다. 오류 :if 문을 사용하여 레이블의 색상을 변경하십시오.
Cannot invoke initializer for type 'Int' with an argument list of type '([String])'
도와주세요.
var percent_change_24hArray = [String]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
let PercentInt = Int(percent_change_24hArray)
if PercentInt < 0 {
cell.procentLabel.textColor = UIColor.red
}
cell.procentLabel.text = "\(percent_change_24hArray[indexPath.row])%"
return cell
}
물론 이것은 'percent_change_24hArray' 배열의 각 요소에 정확히 하나의 행이 있다고 가정합니다. – rmaddy
고마워,하지만 지금은 다른 문제가있다. 그것은 값이 nil이지만, 'cell.procentLabel.text = "\ (percent_change_24hArray [indexPath.row]) %"'가 -17과 같기 때문에 값이 nil이 아니라고 말합니다. – Danjhi
if PerIntInt = Int (percent_change_24hArray [indexPath.row]), PercentInt <0 {...} ' – Annjawn