SlideShare a Scribd company logo
2日間分からなかったので、問
題を整理して解決を試みる
〜ImageView編〜
こじろー
今度こそ本気だして「アプリ開発」やってみる
http://ijoko86-devapplication.blog.jp/
簡単に自己紹介
こじろー
プログラミング経験ほとんどなしの会社員
(唯一Excel VBAだけ経験あり)
iPhoneアプリに挑戦中!
しかし、カメラを使ったアプリに苦戦中…
ブログやってます▶︎今度こそ本気出して「アプリ開発」やってみる
Twitterもやってます。▶︎クリック!
完成型
カメラ
ImageView
カメラボタン押す ▶︎ 次の画面へ遷移しつつ、撮影した画像を次の画面に表示
ViewControllerクラス EditViewControllerクラス
実行の流れ(想定)
1.カメラボタン押されることにより、カメラを呼び出す。
カメラで撮影した画像をImageViewのプロパティに保存。
2.画面遷移(ViewControllerクラスからEditViewControllerクラスへ)
3.画像表示する。
ImageViewに画像を表示する。
1.カメラボタン
カメラ呼び出し、画像取得
2.遷移
画面の遷移
3.画像表示
ImageViewに画像の貼付
こんな感じになる….と思ってた。
事前準備
☝️の画面は以下のようにしてできました。
1.カメラボタンの作成
2.新たにViewController、クラスファイルを作成し、EditViewControllerとする
3.EditViewControllerにImageViewを作成
4.カメラボタンで、EditViewControllerに遷移するようにセグエ
5.カメラボタンから、ViewController.mに接続。メソッド作成(カメラ出す、画像取得する)
6.ImageViewのプロパティをEditControllerに作成する
コードの過程
1.カメラボタン押されることにより、ViewControllerクラス内で以下のメソッドを実行
1.カメラボタン
カメラ呼び出し、画像取得
2.遷移
画面の遷移
3.画像表示
ImageViewに画像の貼付
(コードはテキストのまんま。ここは問題なし)
問題発見
1.続いて、カメラ部での処理内容….のはずが…
1.カメラボタン
カメラ呼び出し、画像取得
2.遷移
画面の遷移
3.画像表示
ImageViewに画像の貼付
(エラー。imageViewプロパティはViewControllerクラスに見つかりません?)
そりゃそうだ。imageViewプロパティは別のクラスで宣言してる!
(EditViewControllerクラスで)
問題とは
1.カメラボタン
カメラ呼び出し、画像取得
2.遷移
画面の遷移
3.画像表示
ImageViewに画像の貼付
問題▶︎ 画像の保存先のプロパティは、撮影とは別のクラスにあった!
解決策▶︎別のクラスにあるプロパティを使えるようになればいい!︎
具体的に何する?? ▶︎検索検索!
Xcode、別のクラスでプロパティ….
…で引っかかったのがこちら。
(えくせぷしょんこーど。 様)
解決策▶︎別のクラスにあるプロパティを使えるようになればいい!︎
AppDelegateに変数書いて参照すれば良い。
以下、自分で分からなくて調べたこと(いや、そっからかよ…ってツッコミはなしで☆)
AppDelegate ▶︎クラス。Project作ったらあるやつ。
アプリの起動時や、バックグラウンド時の処理を担当してる。
(変数を格納できる、という認識はなかった)
変数書いて ▶︎@propertyで宣言。
ちなみに、画像を保存したい場合は?
👉UIImageViewクラスのインスタンス変数を作成。
参照すれば ▶︎AppDelegateクラスを呼び出して、変数を利用可能にする?
(たぶんそんなイメージ)
流れはこう変わる
1.カメラボタン押されることにより、カメラを呼び出す。
カメラで撮影し、AppDelegateを呼び出す。画像をImageViewのプロパティ
AppDelegate内の変数に保存。
2.画面遷移(ViewControllerクラスからEditViewControllerクラスへ)
3.画像表示する。AppDelegateを呼び出して。
ImageViewに画像を表示する。
1.カメラボタン
カメラ呼び出し、画像取得
2.遷移
画面の遷移
3.画像表示
ImageViewに画像の貼付
画面遷移の前後(別クラス)でAppDelegateを呼び出し、変数を利用する。
事前準備も変わる
☝️の画面は以下のようにしてできました。
1.カメラボタンの作成
2.新たにViewController、クラスファイルを作成し、EditViewControllerとする
3.EditViewControllerにImageViewを作成
4.カメラボタンで、EditViewControllerに遷移するようにセグエ
5.カメラボタンから、ViewController.mに接続。メソッド作成(カメラ出す、画像取得する)
6.ImageViewプロパティをEditControllerAppDelegate.hに作成する
AppDelegate内に宣言
UIImageViewクラスのimageView変数を宣言。
▶︎これにより、他のクラスで画像のデータを読み書き可能に!
Appdelegateの呼び出し
まず、ヘッダファイルを読み込み…
コードを書き足したら、エラーでない!!バンザイ!!!
ここでは、カメラ撮影した画像をimage変数(ここで宣言)に保存し、
呼び出したデリゲートのimageView変数に、画像を格納してます。
書き込みまではOK
1.カメラボタン押されることにより、カメラを呼び出す。
カメラで撮影し、AppDelegateを呼び出す。画像をImageViewのプロパティ
AppDelegate内の変数に保存。
2.画面遷移(ViewControllerクラスからEditViewControllerクラスへ)
3.画像表示する。AppDelegateを呼び出して。
ImageViewに画像を表示する。
1.カメラボタン
カメラ呼び出し、画像取得
2.遷移
画面の遷移
3.画像表示
ImageViewに画像の貼付
画面遷移の前後(別クラス)でAppDelegateを呼び出し、変数を利用する。
いけた!
そのまま!
次はココ!
遷移後どうするか
遷移したら、画像を表示すれば良い。
▶︎ボタンとか押さずに、すぐに表示したい▶︎ViewDidLoad?
実装…
画面が変更した際に、実行される!
さっきと同じように、AppDelegateを呼び出して、
imageView変数(画像保存してある)の画像データを、表示部に写す!
….いけるでしょ!
と、ところが….
あれ?
画像が表示されてない!
いやいや、それ以前にカメラが表示されない!
ちょっと休憩&感想
まずは「変数を次のビューに渡す」ということはできた(と思われる)
けっこう記述とかに苦労してたり…(基本を理解できてない証拠)
やっぱりやってみないとわからない(文章読むだけじゃ無理ー)
やってみることで、色々と理解できた
自分の考えてることを文章で起こすのは重要
(自分の頭で回しきれないので…パワポは図も作りやすく、重宝します)
▶︎次の課題は「遷移とコードの順序」!
たぶん、遷移とコードを同時に入れると、順番ごっちゃになるんじゃないかな?
今回はここまで。

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Image view問題