2016-06-26 7 views
-1

私はSwift 2(3.0ではない)でアプリケーションを作成しています。私のTableviewにJSONが表示されるようになりましたが、各セルの結果ではなく、各セルのすべての結果が表示されます。ここで問題Picture of problemスウィフトのJSONの結果は、各セルの各結果ではなく結果のリストを表示します。

マイMasterViewControllerを示す写真です:

import UIKit 
import Alamofire 
import SwiftyJSON 

class MasterViewController: UITableViewController { 

var tableTitle = [String]() 
var tableBody = [String]() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    getJSON() 

} 

func getJSON() { 

    Alamofire.request(.GET, "http://www.graydoncs.club/api/posts").responseJSON { (Response) in 

     if let value = Response.result.value { 

      let json = JSON(value) 

      for anItem in json.array! { 

       let title: String? = anItem["title"].stringValue 
       self.tableTitle.append(title!) 
       print(anItem["title"].stringValue) 

      } 

      dispatch_async(dispatch_get_main_queue()) { 

       self.tableView.reloadData() 

      } 

     } 

    } 

} 

override func viewWillAppear(animated: Bool) { 
    self.clearsSelectionOnViewWillAppear = self.splitViewController!.collapsed 
    super.viewWillAppear(animated) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Segues 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == "showDetail" { 
     if let indexPath = self.tableView.indexPathForSelectedRow { 
      let object = tableTitle[indexPath.row] as! String 
      let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController 
      controller.detailItem = object 
      controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem() 
      controller.navigationItem.leftItemsSupplementBackButton = true 
     } 
    } 
} 

// MARK: - Table View 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 1 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return tableTitle.count 
} 

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 

    let object = tableTitle[indexPath.row] as! String 
    cell.textLabel!.text = tableTitle.description 
    return cell 
} 

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // Return false if you do not want the specified item to be editable. 
    return false 
} 


} 

この問題に関する任意の助けいただければ幸いです。ありがとう!

+0

*ヒント:* 'let object = ... 'に割り当てられたオブジェクトはまったく使用されません。 - コンパイラの警告がありません "不変の値の初期化 'オブジェクト'は使用されていませんでしたか? –

答えて

1
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 

let object = tableTitle[indexPath.row] as! String 
cell.textLabel!.text = object 
return cell 

}