>

viewWillAppear를 호출하면 테이블보기가 새로 고쳐 지지만 데이터가 이상합니다 (새 레코드를 삽입하므로 표시 될 때마다 테이블보기를 새로 고쳐야 함). 원본 데이터 : a, b, c 하나의 레코드를 삽입하십시오 : a, b, c, d 결과 : a, b, c, a (왜 a?) 누군가 나를 도울 수 있기를 바랍니다.

import UIKit
import SQLite
class DetailViewController: UIViewController, UITableViewDelegate, 
UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!

let inputDetailTable = Table("input_detail")
var labelOneArray = [String]()
var labelTwoArray = [NSAttributedString]()
var labelThreeArray = [String]()
var labelFourArray = [String]()
let id = Expression<Int>("id")
let deleteFlag = Expression<Int>("delete_flag")
//    var selectedDatas :AnySequence<Row>!

let viewService = ViewService()
override func viewDidLoad() {
    super.viewDidLoad()
    getTableViewData()
}
override func viewWillAppear(_ animated: Bool) {
    getTableViewData()
    self.tableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection 
section: Int) -> Int {
    let selectedDatas = viewService.selectTableData()
    var counter = 0
    for _ in selectedDatas{
        counter += 1
    }
    return counter
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: 
IndexPath) -> UITableViewCell  {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", 
for: indexPath) as! DetailTableViewCell
    cell.labelOne.attributedText = labelTwoArray[indexPath.row]
    cell.labelTwo.text = labelFourArray[indexPath.row]
    return cell
}
func getTableViewData() {
    let selectedDatas = viewService.selectTableData()
    for selectedData in selectedDatas{
        var tempAmount = String(selectedData[Expression<Int>
("amount")])
        var tempTwoAmout :NSAttributedString?
        if selectedData[Expression<Int>("type_flag")] == 0 {
            tempAmount = "-"+tempAmount
            let text = tempAmount
            let nsText = text as NSString
            let textRange = NSMakeRange(0, nsText.length)
            let myMutableString = NSMutableAttributedString(
                string: tempAmount,
                attributes: [:])
            myMutableString.addAttribute(
                NSAttributedStringKey.foregroundColor,
                value: UIColor.red,
                range: textRange)
            tempTwoAmout = myMutableString
        } else {
            tempAmount = "+"+tempAmount
            let text = tempAmount
            let nsText = text as NSString
            let textRange = NSMakeRange(0, nsText.length)
            let myMutableString = NSMutableAttributedString(
                string: tempAmount,
                attributes: [:])
            myMutableString.addAttribute(
                NSAttributedStringKey.foregroundColor,
                value: UIColor.green,
                range: textRange)
            tempTwoAmout = myMutableString
        }
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
        let createTimeFormat = formatter.string(from: 
selectedData[Expression<Date>("create_time")])
        self.labelOneArray.append(String(selectedData[Expression<Int>
("id")]))
        self.labelTwoArray.append(tempTwoAmout!)
self.labelThreeArray.append(String(selectedData[Expression<String>
("location")]))
        self.labelFourArray.append(createTimeFormat)
    }
}
}


  • 이전 angular2 routing - Angular CLI 'tsc'명령이 dist 폴더에 indexhtml, nodemodules, css 등을 복사하지 않습니다
  • 다음 mysql - 값이 1 일 때 SQL 수