В представлении таблицы не отображаются данные? [закрыто]IOS

Программируем под IOS
Ответить
Anonymous
 В представлении таблицы не отображаются данные? [закрыто]

Сообщение Anonymous »

My tableView не отображает данные. Я получаю данные через API и сохраняю их в отдельный класс с инициализаторами, но они не отображаются в tableView. Как решить эту проблему. Я новичок в iOS. Я знаю, что где-то есть проблема только с одной строкой кода.
Я вызываю API в методе viewDidLoad:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)

//fetch all expected visitor data
self.apiExpectedVisitor(strURL: urlViewExpectedVisitors)
self.expectedTableView.reloadData()
}

Функция метода API
func apiExpectedVisitor(strURL: String)
{
fetchedExpectedData = []

//URL
let myURL = URL(string: strURL)

//URL Request
let request = NSMutableURLRequest(url: myURL!)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Accept")
let token = "Bearer " + strToken
request.addValue(token, forHTTPHeaderField: "Authorization")

let postTask = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) in
print(response!)

guard error == nil else {
return
}

guard let data = data else {
return
}

do {
//create json object from data
if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: [Any]] {
print("POST Method :\(json)")

DispatchQueue.main.async {

for expectedVisitors in json["expected_visitors"]!
{
let eachData = expectedVisitors as! [String: Any]

let id = eachData["id"] as! Int
let name = "\(String(describing: eachData["name"]))"
let email = "\(String(describing: eachData["email"]))"
let phone = eachData["phone"] as! String
let verification_code = "\(String(describing: eachData["expected_visitor_verification_code"]))"
let qr_code = eachData["expected_visitor_qr_code"] as? String
let isVisited = eachData["is_visited"] as! Int
let company_id = eachData["company_id"] as! Int
let purpose = "\(String(describing: eachData["purpose"]))"
let meeting_date = eachData["meeting_date"] as! String
let meeting_time = eachData["meeting_time"] as! String
let created_at = eachData["created_at"] as! String
let updated_at = eachData["updated_at"] as! String

//Date.formatter(createdDate: createdDate)

if let department_id = eachData["department_id"] as? Int, let employee_id = eachData["employee_id"] as? Int, let location_id = eachData["location_id"] as? Int, let image = eachData["image"] as? String, let duration = eachData["duration"] as? String {

fetchedExpectedData.append(FetchedAllExpectedVisitors.init(id: id, name: name, email: email, phone: phone, department_id: department_id, employee_id: employee_id, location_id: location_id, image: image, verification_code: verification_code, qr_code: qr_code!, isVisited: isVisited, company_id: company_id, purpose: purpose, meeting_date: meeting_date, meeting_time: meeting_time, duration: duration, created_at: created_at, updated_at: updated_at))

self.expectedTableView.reloadData()
}
}
}

}
} catch let error {
print(error.localizedDescription)
}
}
postTask.resume()

}

TableView Источник данных и делегаты Методы
func numberOfSections(in tableView: UITableView) -> Int {
return fetchedExpectedData.count
}

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ShowExpectedCell", for: indexPath) as! ShowExpectedTVCell

cell.lblDate.text = fetchedExpectedData[indexPath.section].created_at
cell.lblVisName.text = fetchedExpectedData[indexPath.section].name
print(fetchedExpectedData[indexPath.section].name)

for i in 0..

Подробнее здесь: https://stackoverflow.com/questions/500 ... w-the-data
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»