Objective-Cのエラーコードの意味

このQ&Aのポイント
  • Objective-Cのエラーコードの意味について説明します。
  • エラーコードの意味を理解することで、デバッグの効率が上がります。
  • エラーメッセージをよく読んで、適切な対処方法を見つけましょう。
回答を見る
  • ベストアンサー

Objective-Cのエラーコードの意味

タイトルの通りです。 エラー部分は最下部にあります。 ------------------------------------------------------------------------------------------------- // // ViewController.m // Kadai // // Created by on 2014/08/10. // Copyright (c) 2014年 saikoro. All rights reserved. // #import "ViewController.h" @interface ViewController () <UIAlertViewDelegate> @property (weak, nonatomic) IBOutlet UITextField *tfMyouji; @property (weak, nonatomic) IBOutlet UITextField *tfName; @property (weak, nonatomic) IBOutlet UILabel *Aisatsu; @end @implementation ViewController // 画面タッチ時 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // キーボード非表示 [self.tfMyouji resignFirstResponder]; [self.tfName resignFirstResponder]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } // [挨拶する]ボタン押下 - (IBAction)introduce:(id)sender { UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"確認" message:@"挨拶しますか?" delegate:self cancelButtonTitle:@"キャンセル" otherButtonTitles:@"はい", nil]; // 表示 [av show]; } // AlertViewボタン押下 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"再確認" message:@"本当に挨拶しますか?" delegate:nil cancelButtonTitle:@"やっぱりやめときます" otherButtonTitles:@"早く!", nil]; [av show]; } // AlertViewボタンさらに押下 + (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ // 入力された名前の保持 NSString *str = self.tfMyouji.text; ←ここでエラーが出ます。なぜか「tfMyouji」が                    予測で出てきません } @end ------------------------------------------------------------------------------------------------- どなたかエラーの理由をご教授頂けないでしょうか。 以上、何卒宜しくお願い致します。

noname#213637
noname#213637

質問者が選んだベストアンサー

  • ベストアンサー
  • harawo
  • ベストアンサー率58% (3742/6450)
回答No.1

エラーメッセージを載せてないのに、「エラーコードの意味」を教えてくれ、というのは筋が通っていないような? 「エラーの理由」は、回答可能でしょう。 クラスメソッド内で、「self」が使えないから。 もうすこし詳しく説明すると、インスタンスメソッド内では、selfはインスタンスのことを指しますが、クラスメソッド内では、クラスのことを指します。この場合のselfは、プロパティを呼ぶものであって、インスタンスを指すselfです。 「なぜか「tfMyouji」が予測で出てきません」というのも、クラスメソッド内で、プロパティが使えないから。 いちど「クラスメソッドとはなにか?」を勉強しなおしてください。たぶん、あなたはクラスメソッドを使おうと意図していないのだとは、思いますけどね。

noname#213637
質問者

お礼

失礼致しました。ありがとうございました!

関連するQ&A

  • 【iOS】pickerViewを隠すには?

    pickerViewを、画面のどこかをタップすることで隠すには どのようにすればよろしいでしょうか。 現在のコードです。 TextFieldの代わりにピッカーを出すという実装です。 ヘッダー @property(nonatomic,weak)IBOutlet UITextField *textField; @property(nonatomic,strong)UIPickerView *pickerView; @property(nonatomic,strong)NSArray *items; メイン - (void)viewDidLoad { self.items = @[@"A",@"B",@"C",@"D"]; self.pickerView = [[UIPickerView alloc]init]; self.pickerView.dataSource = self; self.pickerView.delegate = self; self.pickerView.showsSelectionIndicator = YES; self.textField.inputView = self.pickerView; [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return [self.items count]; } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ return [self.items objectAtIndex:row]; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ self.textField.text = [self.items objectAtIndex:row]; } - (IBAction)pressHide:(id)sender{ [self.textField resignFirstResponder]; }

  • objective-c 初心者です

    はじめまして。iphone アプリ開発を始めようと思い、まずは簡単なアプリからと人のまねをして時計アプリを書いております。http://www.slideshare.net/takuya0429/121216の43枚目のスライドを丸写しにしました。しかし、iPhoneシミュレーター(iphone 6.1)でシミュレーションしても真っ黒な画面が移されるだけで思うように機能しません。 なぜ機能しないかを考えられる範囲でご教授願いたい次第です。 環境はmacbook air 13inch にてXcode 4.6.3を使用しております。 以下に作成したコードを記載いたします。 // // ViewController.h // watch // // Created by motoyama kaoru on 2013/08/15. // Copyright (c) 2013年 motoyama kaoru. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *timeLabel; @end // // ViewController.m // watch // // Created by motoyama kaoru on 2013/08/15. // Copyright (c) 2013年 motoyama kaoru. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES]; } -(void)update{ NSDate *now = [NSDate date]; NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"HH:mm:ss"]; self.timeLabel.text = [df stringFromDate:now]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

  • iPhoneアプリ作成時のXcodeのエラー

    はじめまして。 iPhoneのアプリ作成に挑戦しています。 Xcode4のバージョンは 4.5.1です。 【はじめてのXcode4プログラミング】という参考書でIPhoneのカメラアプリを作る章があり、写真ライブラリから選択した画像を表示できるとのことです。 しかし、XcodeでRun(実行)すると、ViewController.mの最後から4行目【UIImage *originalImage = [info objectForkey:UIImagePickerControllerOriginalImage];】が赤くなり、【No visible @interface for 'NSDictionary' declares the selector 'objectForkey'】というエラー表示がでます。 全体のコードは下記の通りです。 ネットで調べてみましたが、解決方法がわかりません。 先に進めず困っています。 どうか解決方法を教えてください。 よろしくお願い致します。 ●ViewController.h// // ViewController.h // CameraApp // #import @interface ViewController : UIViewController - (IBAction)pressCameraButton:(id)sender; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end ●ViewController.m // // ViewController.m // CameraApp // #import “ViewController.h” @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)pressCameraButton:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [[self presentViewController:picker animated:YES completion:nil];} - (void)imagePickerController:(UIImagePickerController*)Picker didFinishPickingMediaWithInfo:(NSDictionary*)info { [self dismissViewControllerAnimated:YES completion:nil]; UIImage *originalImage = [info objectForkey:UIImagePickerControllerOriginalImage]; // ↑↑ 上記の行でエラーが出ます self.imageView.image = originalImage; } @end

  • swift言語 Xcode

    アプリを作る勉強をしています。参考書通りやりましたが、警告が出てしまいます。 原因がわからず困っています。どなたか助けて頂けませんでしょうか?宜しくお願い致します。 ソースはこちらです。 import UIKit import MapKit class ViewController: UIViewController ,UITextFieldDelegate { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. inputText.delegate = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBOutlet weak var inputText: UITextField! @IBOutlet weak var dispMap: MKMapView! } func textFildShoouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() let searchKeyword = textField.text print(searchKeyword) ⇦ここに警告が出ます。 return true

  • Xcode4のエラー(IPhoneアプリ)

    はじめまして。 IPhoneのアプリ作成に挑戦しています。 Xcode4のバージョンは 4.5.1です。 【はじめてのXcode4プログラミング】という参考書でIPhoneのカメラアプリを作る章があり、写真ライブラリから選択した画像を表示できるとのことです。 しかし、XcodeでRun(実行)すると、ViewController.mの最後2行【UIImage *originalImage =[info objectForkey:UIImagePickerControllerOriginalImage];】が赤くなり、【’dismissModalViewControllerAnimated’is deprecated: first deprecated in iOS 6.0】というエラー表示がでます。 全体のコードは下記の通りです。 ネットで調べてみましたが、解決方法がわかりません。 先に進めず困っています。 どうか解決方法を教えてください。 よろしくお願い致します。 ●ViewController.h// // ViewController.h // CameraApp // #import @interface ViewController : UIViewController - (IBAction)pressCameraButton:(id)sender; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end ●ViewController.m // // ViewController.m // CameraApp // #import “ViewController.h” @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)pressCameraButton:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:picker animated:YES]; } - (void)imagePickerController:(UIImagePickerController*)Picker didFinishPickingMediaWithInfo:(NSDictionary*)info { [self dismissModalViewControllerAnimated:YES]; UIImage *originalImage = [info objectForkey:UIImagePickerControllerOriginalImage]; self.imageView.image = originalImage; } @end

  • Objective-C,viewが動作しない

    IBを使わないカメラアプリを作っています。 AppDelegate.m内のapplication didFinishLaunchingメソッド内で生成したwindowとviewはコンパイルして表示確認できたのですが、viewControllerで書いたUIImagePickerViewControllerのviewが出てきません。 そもそもviewController.mのloadViewメソッドやviewDidLoadメソッドが動いていません。(メソッド内にNSLogを書いてコンパイルしてもログに出ない) viewController.h #import <UIKit/UIKit.h> @interface CameraViewController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate> { @private UIImagePickerController* _imagePicker; } @property(nonatomic,retain) UIImagePickerController *imagePicker; @end viewController.m #import "CameraViewController.h" @implementation CameraViewController @synthesize imagePicker=_imagePicker; - (void)dealloc { [super dealloc]; } #pragma mark - View lifecycle - (void)loadView { [super loadView]; //UIImagePickerControllerの作成 if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ return; } UIImagePickerController* imagePicker; imagePicker = [[UIImagePickerController alloc] init]; [imagePicker autorelease]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.allowsEditing=NO; imagePicker.delegate = self; //imagePickerのviewを最上部に [self presentModalViewController:imagePicker animated:YES]; //シャッターを切る [self.imagePicker takePicture]; } @end viewControllerが機能しない原因としてそういった可能性が考えられるのでしょうか? あれこれ調べてみましたが煮詰まっています。よろしくお願いします

  • iosプログラムで背景色をコードで変更するには?

    xcodeでiphone用のアプリを作りたいと思い、プログラミングをやっています。 ラベルボタンを押したら背景色を変更するようなプログラムをしたいと思っています。 class ViewController : UIViewController { @IBOutlet weak var textfield: UITextField! @IBAction func sayhello(sender: AnyObject) { textfield.text = "Hello world!" } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } このhello worldをやった時に作成したプロジェクトを使用して、ボタンを押したら背景を任意の色(今回は黒)に変えたいと思っています。 それでこのクラス関数内にMystorlyboardウィンドウから背景を"control"ボタンをクリックしながら @IBOutlet var background: UIView! というのを追加しました。 そして、押すと"hello world"とテキストボックスに表示するボタンの処理の中に background.backgroundColor = Black としてみたのですが、エラーが出てビルドが成功しません。 (エラー内容)”Use of unresolved identifier ''Blue' この場合どのようにコードを修正するべきでしょうか? どうぞ、ご教示頂きますよう、よろしくお願い致します。 (現在のコード内容) import UIKit class ViewController: UIViewController { @IBOutlet var background: UIView! @IBOutlet weak var textfield: UITextField! @IBAction func sayhello(sender: AnyObject) { textfield.text = "Hello world!" background.backgroundColor = Blue } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }

  • objective-c 画面遷移について

    プログラミングに関して素人です。 UIViewControllerからPushコードを使って別のUIViewに画面遷移したいのですが 遷移先にTableViewを2つ並べております。 画面遷移する際のコードはどのように記述したらいいのでしょうか? 詳しいかたお力お貸しいただければと思います。 ViewController.m - (IBAction)NewsPage:(UIButton *)sender { //こちらの記述方法が不明 } TViewController.h // XibファイルとUIViewの紐づけ。 @property (weak, nonatomic) IBOutlet UITableView *leftTableView; @property (weak, nonatomic) IBOutlet UITableView *rightTableView; - (IBAction)TopButton:(UIButton *)sender; 根本的になにか違えばご指摘お願いします。

  • XcodeのObjective-Cについて

    大変初歩的な質問でお恥ずかしいのですが、最近Xcodeを初めて本で少しずつObjective-Cを勉強中の初心者です。 MainStoryboardでLabelをViewに配置した後、 「画面を表示する準備ができたときにコンソール画面に"こんにちは"と表示させるプログラムを追加」というものが載っているのですが、指示通り打ち込んでもエラーでうまくいきません。 本には「m.」ファイル上の「@implementation」の次の行に 01 - (void)viewDidLoad 02 { 03   [super viewDidLoad]; 04   NSLog(@"こんにちは"); 05 } とあり、その通りに打ち込んだのですが(以下Xcodeよりコピペ) @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"こんにちは"); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } となり、 NSLog(@"こんにちは"); } の次の行の - (void)viewDidLoad に赤い!マークのエラーが表示されてしまいます。 初心者のため訂正方法もわからずネット検索しても解決しなかったので、 大変申し訳ないのですが教えていただきたく思います。

  • objective-cで困っています教えてください

    下記のようにUIViewの上にUIImageViewを配置し、そこにUIImageをUIViewContentModeScaleAspectFitで表示させています。 表示している画像タップして、座標をとりたいと考えています。 UIImageView(UIImage)上だけをタップのエリアにしたいのですが、画面全体がタップのエリアになってしまいます。また、画像のアスペクト比を維持しUIImageViewサイズに収まるように表示しているので、タップでとれたUIImageView上の座標と、画像上の座標にズレができてしまいます。UIImageViewサイズに収まるように表示された画像上の位置から元の画像の座標を取得する方法を教えてください。 #import "ViewController.h" @interface ViewController (){ UIImageView *imageView; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CGRect rect = CGRectMake(0,20, 360, 480); imageView = [[UIImageView alloc] initWithFrame:rect]; imageView.backgroundColor = [UIColor redColor]; //画像のアスペクト比を維持しUIImageViewサイズに収まるように表示 imageView.contentMode = UIViewContentModeScaleAspectFit; UIImage *image = [UIImage imageNamed:@"hoge.png"]; [imageView setImage:image]; [self.view addSubview:imageView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /** * タッチされたとき */ - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint p = [[touches anyObject] locationInView:imageView]; float x = p.x; // X座標 float y = p.y; // Y座標 NSLog(@"タップ開始 %f, %f", x, y); } @end

専門家に質問してみよう