
こんにちは、ススムです。

Swiftについて興味があって、これから勉強したい!
現在、Swift学習中です!
そんな方向けの記事内容となります。
この記事を書いた人はこんな感じです。⇩
著者
- スポーツの専門学校卒業
- オーストラリアへ語学留学/スシレストランで就労
- JICA海外協力隊にてミャンマーで2年間生活
- Webデザイナー/動画クリエイター/Webエンジニア/Webライター
- オンラインスポーツコーチ
- オンライン日本語講師
- オンラインミャンマー語講師
- ミャンマー人向けオンラインコミュニティ運営
※この記事を書いている私について詳しくはこちらで紹介しています。
本記事の内容
・UITableViewとは
・日時の表示の仕方
【エンジニアの職探しならこちら🔻】
フリーランスエンジニアに安心保証と豊富な案件紹介を【midworks】
UITableViewとは
UITableViewとは、配列で格納されたデータをリストとして画面に表示したい場合に使用
します。
UITableViewは1つの表示する項目をセルといいます。
このセルの使用にはUITableViewCellを用います。 また、TableViewの使用には「delegate」「datasource」機能を用います。
では、実際にコードをみていきます。

TableViewを配置しました。
続いてTableViewCellを配置します。

これらを配置し終えたので、delegateとdatasourceの設定を行います。

datasourceは、テーブルビューのデータソースとして機能するオブジェクトです。 delegateは、リストの行数を返す、セクション数を返すなどのデリゲードメソッドをViewControllerにデリゲードする必要があり、TableViewをVIewcontrollerボタンまで ドラッグします。

datasourceとdelegateを選択しました。

TableViewCellのideatifierからセルの名称を指定しました。
情報を表示させる
TableViewに情報を表示させるためにViewController.swiftを編集します。

TableViewをViewController.swiftに追加しました。

DatasourceとDelegateを使用するため、UITableViewDelegate, UITableViewDataSourceを追加しました。

エラーを防ぐためにDelegateとUITableViewDataSourceメソッドを追加しました。
tableView.dequeueReusableCellでは、TableViewCellで設定した「sample1」を指定 しました。
Dateで日付を取得

まず現在の日時を表示するにはDateを用います。
let date:Date=Date()
print(date)
続いて指定した日時を表示するにはCalendarのインスタンスを使用すると特定の日時を取得できます。
let calendar = Calendar.current let date=Date()
let day_tomorrow=calendar.date(
byAdding:.day,Value:1, to:calendar.start0fDay(for: date))
let day_yesterday=calendar.date(
byAdding:.day,value: =1,to:calendar.start0fDay(for:date))
valueの値を1(明日)、–1(昨日)を指定して日付を取得します。
日付をフォーマット
DateFormmaterを使用して、日付を指定します。
let date:Date=Date()
let format=DateFormatter() format.dayeformat=”yyyy/MM/dd HH:mm:ss”
let sDate=format.string(from:date) print(sDate)
DatePicker
xcodeのDatePickerを使用して選択した日付を表示してみます。
まずDatePickerを配置しました。

続いてlabelとbuttonを配置しました。

ViewController.swiftへ各コードをリンクさせます。
これをビルドして動かしてみると以下のように表示されます。


プログラミング学習ツール
https://prog-8.com/languages
https://dotinstall.com/
私は、エンジニアの学習にあたってこちらの資料を参考にしました。
http://www5e.biglobe.ne.jp/aji/3min
https://ping-t.com/
【エンジニアの職探しならこちら🔻】
フリーランスエンジニアに安心保証と豊富な案件紹介を【midworks】
【IT・プログラミング関連記事】
また、何かあったら紹介したいと思います。
質問などがあれば気軽にコメント下さい。
仕事の依頼などがあればメールまたはSNSにてお問い合わせ下さい。
以上が今回のブログとなります。
読んで頂きありがとうございます。
また次回お会いしましょう。
※0円で受けれるプログラミング説明会
今話題のテックキャンプ。
実績、知名度ともに業界最大級の未経験を対象としたテクノロジースクールです。 受講期間中はいつでもメンター(講師)に質問ができ、目的達成のためにトレーナーが徹底的にサポートします。


【ミャンマー写真集】
【ミャンマー語学習教材3選】
※ミャンマー語のテスト問題集作成しました。詳しくはこちらから
※ミャンマースポーツコミュニティ⏩【Myanmar Sports/ISPE】
※ミャンマー✖️日本コミュニティー⏩【MyanJapa Life】

企業の方、プレスの方、個人の方など、仕事の依頼に関するお問い合わせは以下の
フォームからお気軽にご連絡下さい
コメント