-1
這是我必須在主表格視圖控制器上使用的代碼我只是不知道如何去轉換到新的視圖控制器以顯示選定的單元格有關選擇任何單元格的更多內容。如何從Swift中的表格單元格中移除
import UIKit
class MainVC: UITableViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var Table1: UITableView!
var postArray: [[String]] = []
var postSubject = ""
var postDescription = ""
var postDate = ""
override func viewDidLoad() {
super.viewDidLoad()
fetchData()
}
func fetchData() {
println("success1")
postArray = []
let httpMethod = "GET"
let timeout = 15
let urlAsString = "http://cgi.soic.indiana.edu/~team12/main_requests.php"
let url = NSURL(string: urlAsString)!
let urlRequest = NSMutableURLRequest(URL: url,
cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 15.0)
urlRequest.HTTPMethod = httpMethod
let queue = NSOperationQueue()
println("success2")
NSURLConnection.sendAsynchronousRequest(urlRequest,
queue: queue,
completionHandler: {(response: NSURLResponse!,
data: NSData!,
error: NSError!) in
if data.length > 0 && error == nil{
let html = NSString(data: data, encoding: NSUTF8StringEncoding)
} else if data.length == 0 && error == nil{
println("Nothing was downloaded")
} else if error != nil{
println("Error happened = \(error)")
}
if data.length > 0 && error == nil {
let html = NSString(data: data, encoding: NSUTF8StringEncoding)
var newArrayofDicts : NSMutableArray = NSMutableArray()
var arrayOfDicts : NSMutableArray? = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error:nil) as? NSMutableArray
println("successmutable")
if arrayOfDicts != nil {
for item in arrayOfDicts! {
if var dict = item as? NSMutableDictionary{
if dict["subject"] != nil{
self.postSubject = dict["subject"] as String
self.postDescription = dict["subject"] as String
self.postDate = dict["date"] as String
self.postArray.append([self.postSubject,self.postDescription,self.postDate])
println("successpost")
}
}
}
}
}
}
)
sleep(1)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
fetchData()
tableView.reloadData()
println("successanime")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
println("successoverride")
let cell = tableView.dequeueReusableCellWithIdentifier("UpdateCell", forIndexPath: indexPath)
as UITableViewCell
println("successupdatecell")
cell.textLabel.text = postArray[indexPath.row][1]
cell.detailTextLabel?.text = postArray[indexPath.row][2]
println("success3")
return cell
}
執行從表視圖SEGUE cell與Swift無關,因爲它不需要代碼就可以做到。如果您正在討論將數據傳遞給下一個控制器,請進行一些搜索。對此,有數百個答案。 – rdelmar 2015-04-01 02:34:49