1
I’m populating a UITableView
with data that I pick up on a Webservice JSON.
These data are texts that I need to format.
It’s coming this way:
My Viewcontroller:
//
// ViewController.swift
// tableView
//
// Created by Gabriel Rodrigues on 03/12/15.
// Copyright © 2015 Sephirot. All rights reserved.
//
import UIKit
import Alamofire
import SwiftyJSON
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var texto: [String] = []@ IBOutlet weak
var table: UITableView!
override func viewWillAppear(animated: Bool) {
self.table.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
table.delegate = self
table.dataSource = self
loadPosts()
}
func loadPosts() {
let url = "http://puc.vc/painel/webservice/procedimentosacademicos/"
Alamofire.request(.GET, url)
.responseJSON {
response in
if
let value: AnyObject = response.result.value {
let post = JSON(value)
for (_, subJson) in post {
self.texto.append(subJson.stringValue)
}
}
dispatch_async(dispatch_get_main_queue(), {
self.table!.reloadData()
})
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) - > Int {
return self.texto.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel ? .text = self.texto[indexPath.row]
print(self.texto[indexPath.row])
return cell
}
}
Example source: Github
1 - How can I accomplish line breaks in large texts?
2 - How can I remove the click event on these lines? or specify a specific one to have the click.
3 - How to define a custom font for this UITableViewCell
?
You can also create a custom Uitableviewcell if you want... Tutorial shrikar.com Tutorial seemuapps.com
– Lucas Eduardo