2017-01-15 8 views
0

私はニュースをtableViewセルに読み込むアプリケーションを作成しました。 これで、ユーザーは個別の記事を開くことができます。 これを行うには、選択したセルをprepareForSegueメソッドを使って渡しました。 タイトルとイメージは正しく渡されますが、フルテキストは部分的に表示され、正確にはセルのように表示されます。ここでprepareForSegue(swift 3)の後にテキストが完全に渡されない

は、ニュースのクラスの私のテーブルです:

import Alamofire //Framework for handling http requests 
    import UIKit 
    import AlamofireImage 


    class NewsTableViewController: UITableViewController { 

//Custom struct for the data 
struct News { 
    let title : String 
    let text : String 
    let link : String 
    let imgUrl : String 

    init(dictionary: [String:String]) { 
     self.title = dictionary["title"] ?? "" 
     self.text = dictionary["text"] ?? "" 
     self.link = dictionary["link"] ?? "" 
     self.imgUrl = dictionary["imgUri"] ?? "" 
    } 
} 

//Array which holds the news 
var newsData = [News]() 

// Download the news 
func downloadData() { 
    Alamofire.request("https://api.sis.kemoke.net/news").responseJSON { response in 
     print(response.request as Any) // original URL request 
     print(response.response as Any) // HTTP URL response 
     print(response.data as Any)  // server data 
     print(response.result) // result of response serialization 

     //Optional binding to handle exceptions 
     self.newsData.removeAll() // clean the data source array 
     if let json = response.result.value as? [[String:String]] { 
      for news in json { 
       self.newsData.append(News(dictionary: news)) 
      } 
      self.tableView.reloadData() 
     } 
    } 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 
    downloadData() 
    tableView.rowHeight = 100 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 

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

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

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? newsCellTableViewCell 
    let news = newsData[indexPath.row] 
    cell?.headline.text = news.title 

    Alamofire.request(news.imgUrl).responseImage { response in 
     debugPrint(response) 
     print(response.request as Any) 
     print(response.response as Any) 
     debugPrint(response.result) 
     let cellImage = response.result.value 
     if let image = response.result.value { 
      print("image downloaded: \(image)") 
     } 
     cell?.thumbnailImage.image = cellImage 
    } 
    print(news.imgUrl) 
    return cell! 
    } 


     // MARK: - Navigation 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "showArticle" { 
     let nextScene = segue.destination as! ArticleViewController 
     // Pass the selected object to the new view controller. 
     if let indexPath = self.tableView.indexPathForSelectedRow { 
      let selectedCells = newsData[indexPath.row] 
      nextScene.articleTitleString = selectedCells.title 
      nextScene.receiveFullText = selectedCells.title 

      //Downloading an image to be displayed in a single article 
      Alamofire.request(selectedCells.imgUrl).responseImage { response in 
       debugPrint(response) 
       print(response.request as Any) 
       print(response.response as Any) 
       debugPrint(response.result) 
       let cellImage = response.result.value 
       nextScene.articleImage.image = cellImage! 
      } 
     } 
    } 
} 
} 

そして、ここでは、私は情報に

class ArticleViewController: UIViewController { 

@IBOutlet weak var articleTitle: UILabel! 
var articleTitleString = "" 
@IBOutlet weak var articleImage: UIImageView! 
@IBOutlet weak var fullText: UITextView! 
var receiveFullText = "" 

override func viewWillAppear(_ animated: Bool) { 
    articleTitle.text = articleTitleString 
    fullText.text = receiveFullText 
} 
} 

を渡しています。これは何が起こるかである単一の物品のための私の先のビューコントローラである

http://imgur.com/2GQddeW

http://imgur.com/jos3VhE

を参照してください。サーバーがフルテキストを返してもフルテキストは表示されません。 私は、別のビューコントローラでtextViewを作成し、サーバーからテキストを取得することでこれをテストし、うまくいきました。

問題は、セル内のラベルのレイアウトをコピーして、そのラベルに何が表示されているかのように見えます。 また、別のラベルをセルに貼り付けて、テキストinitをロードしようとしましたが、セルをタップした後に、ラベル内の内容を表示するよりも正しく機能しました。

私がしたいのは、このセグが起きたときに全文を読み込むことです。

+0

...フルテキストの代わりに二回のタイトルを渡しています。しかし、あなたのテキストはあまりにも多いです。 [ここ](http://candycode.io/automatically-resizing-uitableviewcells-with-dynamic-text-height-using-auto-layout/)と[こちら](http://stackoverflow.com/questions/19211083)を参照してください。/how-to-resize- uitableviewセルフフィットコンテンツへ) – Honey

+0

@Adin Ljudina、間違ったデータを渡したのですか? – aircraft

+0

@Honeyテーブルビューのセルの高さは重要ではありません。重要なのは新しいviewControllerに表示されるテキストです。このスクリーンショットを確認してください。最後の単語 "SEDEF"を見ると3つのドットが表示され、何らかの理由でそれが表示されないため –

答えて

0
nextScene.articleTitleString = selectedCells.title 
nextScene.receiveFullText = selectedCells.title 

あなたは私の知る限り、あなたのtableViewCellは固定の高さを持って理解し

+0

nextScene.receiveFullText = selectedCellsに修正しました。テキスト まだ私のテキストが完全に表示されていません。このスクリーンショットを確認してください。 http://imgur.com/Dxqp9qC –

+0

その場合、2番目のコントローラのUITextViewが十分ではないようです。インタフェースビルダーに行き、黄色の領域をすべて満たしていることを確認します(制約を追加する必要があるかもしれません)。 UITextViewの背景をペイントして、サイズが正しいかどうかを確認することもできます。 –

+0

完全に引き伸ばされているので、画面全体を占有しているので問題ありません。 –

関連する問題