Scenario:
I have a webservice that I use to get texts, these texts can be modified by a web interface, but the title of them will always be fixed, so it was decided to insert them directly into the mobile application.
What I'm currently doing:
I am making a request that transforms this json into an array of strings. After doing the loop and creating this Array With Strings I load a table.
Now, I need to redefine this Array using another fixed array with the Next Structure.
let textoFixo:[String] = ["Titulo 1", "Leia mais", "Titulo 2","Leia mais","Titulo 3"]
Being the Request Array:
let texto:[String] = ["conteudo1","conteudo2","conteudo3"];
Becoming like this:
let texto:[String] = ["Titulo 1","conteudo1","Leia mais","Titulo 2","conteudo2","Leia mais"]
Since the Title should have a larger font in bold and read it more should be directed to another screen, which will be static also being triggered by a pushViewController:
self.navigationController!.pushViewController(newViewController, animated: true)
Implementation:
import UIKit
import MMDrawerController
import SwiftyJSON
class FooViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var texto = [String]()
@IBOutlet weak var table: UITableView!
override func viewDidLoad() {
let load = Loader(view: self.view) // progress loader
table.delegate = self
table.dataSource = self
table.rowHeight = UITableViewAutomaticDimension
table.estimatedRowHeight = 44.0
let api = API()
api.get("foo") { responseObject, error in // request json data
let value = JSON(responseObject!)
for (_, subJson) in post { // fill array of strings
self.texto.append(subJson.stringValue)
}
self.table!.reloadData() // load de table with the data
load.stop(self.view)
}
}
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 = tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
cell.textLabel?.text = self.texto[indexPath.row]
return cell
}
}
It can occur if the structure is broken if there are two contents, each one being a paragraph.