質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
RSS

RSS(Really Simple Syndication)はブログのエントリやニュースの見出し、標準のフォーマットの音声やビデオなどを発行するために使われるウェブフィードのフォーマットの集合体です。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

0回答

1386閲覧

TableViewの各セルのカスタマイズ方法

MItsuko

総合スコア6

RSS

RSS(Really Simple Syndication)はブログのエントリやニュースの見出し、標準のフォーマットの音声やビデオなどを発行するために使われるウェブフィードのフォーマットの集合体です。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/07/11 06:25

###前提・実現したいこと
現在、独学でswiftを学習しており、RSSを使った2chまとめリーダのようなものを作っています。
TableViewの各セルに記事のタイトルを表示し、それをタップするとWebViewを使って記事を表示するところまで実装できています。
現在、1つのサイトのRSSしか使っていないのですが、実際の2chまとめリーダのように複数のサイトのRSSデータを取得し、それをランダムに表示したいと考えています。
ネットで調べても実装方法が出てこず、文系の学生のため周りに聞く人がおらず困っています。
お力添え、よろしくお願いします。
###該当のソースコード
学習を初めてまだ1ヶ月のため、稚拙なコードで申し訳ございません。

TableViewController

import UIKit

class TableViewController: UITableViewController,XMLParserDelegate {

var parser:XMLParser! var items = [Item]() var item:Item? var currentString = "" class Item{ var title = "" var link = "" } override func viewDidLoad() { super.viewDidLoad() // Uncomment the following line to preserve selection between presentations // self.clearsSelectionOnViewWillAppear = false // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func reloadButton(_ sender: Any) { self.startdownload() self.tableView.reloadData() } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 100 } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { //#warning Incomplete implementation, return the number of rows return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = items[indexPath.row].title // Configure the cell... return cell } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) startdownload() } func startdownload(){ self.items = let url_text = "http://alfalfalfa.com/index.rdf" guard let url = NSURL(string: url_text) else{ return } // インターネット上のXMLを取得し、NSXMLParserに読み込む guard let parser = XMLParser(contentsOf: url as URL) else{ return } parser.delegate = self; parser.parse() } func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { self.currentString = ""//一旦空に if elementName == "item"{ self.item = Item() } } func parser(_ parser: XMLParser, foundCharacters string: String) { self.currentString += string } func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { switch elementName{ case "title":self.item?.title = currentString case "link":self.item?.link = currentString case "item":self.items.append(self.item!) default:break } } func parserDidEndDocument(_ parser: XMLParser) { self.tableView.reloadData() }

###試したこと
インターネットで調べた

###補足情報(言語/FW/ツール等のバージョンなど)
Xcode 8.3.3

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問