- ベストアンサー
Object-Cのsetの後ろにプロパティ名が?
- object-cのカテゴリが無いのでこちらで質問です。
- Questionは、ほかの.hファイルで@property (retain, nonatomic) NSString *question;と書かれているのでプロパティだと想像しています。
- プロパティ名にsetをつける文法があるのでしょうか?本を4冊調べて、ぐぐりもしましたがわかりません。申し訳ございませんが教えてください。
- みんなの回答 (3)
- 専門家の回答
関連するQ&A
- インスタンス変数の参照について
おせわになります。 iOS xcodeのビギナーです。 ひとつのクラスで定義したインスタンス変数を、別のクラスで参照しようとしても、 内容がnilとなってしまいます。 参考書やインターネットでいろいろ調べたのですが、混乱してしまっております。 よろしくお願い致します。 RootViewController.h RootViewController.m OAutoView.h OAutoView.m RootViewContrller で取得した文字データを、OAutoView上のtextViewで表示したいのですが、 ロジックの問題?で中身にnilが入っているようです。 ------------------------------------------ RootViewController.h @property (retain) NSString *stringValue; ------------------------------------------ RootViewController.m @synthesize stringValue; - (NSString *)stringValue{ return stringValue; } - (void)setstringValue:(NSString *)value{ stringValue = value; } 下記でsDataをstringValueへセットしています。 sDataの中には、文字データが入っております。 - (void)tableView....... { stringValue = sData; } ------------------------------------------- OAutoView.h 下記でstringValueを定義したRootViewControllerクラスのインスタントを作成しています。 @class RootViewController; @interface OAutoView : UIViewController { UITextView *textView; RootViewController *rootViewController; } @property (nonatomic, retain) IBOutlet UITextView *textView; @property (retain) RootViewController *rootViewController; @end -------------------------------------------- OAutoView.m 下記で一旦 tDataに、RootViewControllerクラスで作成したstringValueを セットしていますが、既にこの時点で内容はnilのようです。 - (void)viewDidLoad { NSString *tData = [rootViewController stringValue]; rootViewController.stringValue = tData; //[rootViewController setstring:tData] <--なぜかコンバイルエラーとなってしまいます。 textView.text = tData; [super viewDidLoad]; }
- 締切済み
- その他(プログラミング・開発)
- 【Objective-C】プロパテイについて
Objectiv-Cの勉強を始めたばかりの者です。 プロパテイの機能を理解する為に以下のようなプログラムを書きました。 例1)まずは、プロパテイを使わない例です。 ーーーーーーー data.h ーーーーーーー #import <Foundation/NSObject.h> #import <Foundation/NSString.h> @interface Data : NSObject { NSString* str; } - (void)setStr:(NSString* )arg; - (NSString*)retStr; @end ーーーーーーー data.m ーーーーーーー #import "Data.h" @implementation Data - (NSString*) retStr{ return str; } - (void)setStr:(NSString*) arg{ [arg retain]; [str release]; str = arg; } @end ーーーーーーー main.m ーーーーーーー #import <stdio.h> #import "Data.h" int main(void) { Data* data = [[Data alloc] init]; [data setStr:@"aaa"]; NSLog(@"%@",[data retStr]); return 0; } 例2)次に、プロパテイを使って例1を書き換えてみました。 ーーーーーーー data.h ーーーーーーー #import <Foundation/NSObject.h> #import <Foundation/NSString.h> @interface Data : NSObject { NSString* str; } @property (retain) NSString* str; @end ーーーーーーー data.m ーーーーーーー #import "Data.h" @implementation Data @synthesize str; @end ーーーーーーー main.m ーーーーーーー #import <stdio.h> #import "Data.h" int main(void) { Data* test = [[Data alloc] init]; test.str = @"hoge"; NSLog(@"%@",test.str); return 0; } 例2を実行した結果、以下のように出力されました。 2010-02-05 22:17:50.696 data[1583:903] *** __NSAutoreleaseNoPool(): Object 0x100001068 of class NSCFString autoreleased with no pool in place - just leaking 2010-02-05 22:17:50.698 data[1583:903] hoge @propertyのオプションを(retain) ではなく、(assign)に変更すると、 2010-02-05 22:30:02.271 data[1619:903] hoge と出力されて、期待した結果が得られるのですが、なぜretainではダメなのでしょう? また、assignでも例1のようなメモリ管理は自動的に行われているのでしょうか? 以上、ご指導の程、よろしくお願いいたします。
- ベストアンサー
- その他(プログラミング・開発)
- 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 ------------------------------------------------------------------------------------------------- どなたかエラーの理由をご教授頂けないでしょうか。 以上、何卒宜しくお願い致します。
- ベストアンサー
- その他(プログラミング・開発)
- UITableViewの編集モードが実装できない
Objective-Cを用いてiPhoneアプリのプログラミングを勉強しています。 http://konton.ninpou.jp/program/cocoa/userinterface/UITableView/UITableView2.html UITableViewで編集モードを実装したいと思い、こちらのサイトを参考にコードを記述したのですがsignal:SIGABRTが出てしまい、実行できません。 一応build succeedとは出るのですが、iOSシミュレータの最初の画面が表示される前にエラーが出てしまうという状況です。 以下にコードを晒します。 アドバイスお願いしますm(_ _)m ■ヘッダファイル #import <UIKit/UIKit.h> @interface ViewController : UITableViewController { NSMutableArray *stringArray; UITableView *myTableView; } @property (nonatomic, retain) IBOutlet UITableView *myTableView; @property (nonatomic, retain) NSMutableArray *stringArray; @end ■実装ファイル http://www.dotup.org/uploda/www.dotup.org5336157.txt コードが古いようで、ARCエラーが出ましたが、以下のサイトを参考に対策をしたところ、コード上のエラー表示は無くなりました。 http://d.hatena.ne.jp/mTsuruta/20111107/1320615543
- ベストアンサー
- その他(プログラミング・開発)
- IBOutlet が認識されない
Xcode3.2.5 で久しぶりにiPhoneアプリ作成の再勉強をしていますが、 IBOutlet が Interface Builder で認識しません。 手順### 新規プロジェクトで Window-based Application を選択して HelloWorldプロジェクトを作成。 ↓ HelloWorldAppDelegate.h に以下のように記述 #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; IBOutlet UILabel *label; //←追加 } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UILabel *label; //←追加 @end 保存して、MainWindow.xib をクリックし Interface Builder を起動しましたが、 Hello World App Delegate をみても IBOutlet の label が ちゃんと Inspector に表示されません。 以前、前のバージョンのXcodeで作成したものをみてみると ちゃんと反映されるのですが新バージョンのXcodeだと具合が違うようです。 ググってみると http://iphone-ipodtouch-development.blogspot.com/2010/10/inspector.html が一番この例に詳しいようですがうまくいきません。 この解決法の説明をよろしくお願い致します。
- ベストアンサー
- その他(プログラミング・開発)
- iPhone IBを使用しないでUITabBarControllerを
iPhone IBを使用しないでUITabBarControllerを実装 - (void)applicationDidFinishLaunching:(UIApplication *)application { window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // UIViewControllerを継承したクラス page1Controller = [[Page1Controller alloc] initWithNibName:nil bundle:nil]; page2Controller = [[Page2Controller alloc] initWithNibName:nil bundle:nil]; // 質問1 tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil]; [tabBarController setViewControllers:[NSArray arrayWithObjects:page1Controller, page2Controller, nil] animated:NO]; // 質問2 [window addSubview:tabBarController.view]; tabBarController.selectedIndex = 1; } 上記プログラムなのですが、 質問1.UITabBarControllerのsetViewControllersメソッドを利用して、 UIViewControllerのインスタンスをセットしているのですが、 setViewControllersメソッドは、 UITabBarControllerのプロパティviewControllersに 値をセットするためのセッターなのでしょうか? 質問2.[window addSubview:tabBarController.view]のviewは、 UITabBarControllerが継承しているUIViewControllerの view(ゲッター)なのでしょうか? 上記の流れで、UITabBarControllerが、UIVeiwControllerを集約?しているので、 (@property(nonatomic, copy) NSArray *viewControllersとUITabBarControllerのヘルプに明記しているので) WindowのaddSubViewにセットするのは、UITabBarControllerのUIViewControllerのviewじゃないのかな? と初心者ながらの疑問です。 継承などの理解不足があると思いますが、ご教授の程お願いいたします
- 締切済み
- その他(プログラミング・開発)
- C# データバインディングされたプロパティの更新
C#の質問になります。 INotifyPropertyChangedを実装したプロパティをラベルにバインディングして、プロパティの値を表示しています。 ボタンを押下するとプロパティの値を更新するプログラムを追加しました。プロパティの値が変わるとラベルの表記も自動で更新されています。 ある時、プロパティに収める値を演算する処理に3秒掛かるようになりました。結果がラベルに反映されるまでの時間は重要ではないため、この部分をスレッド化しようと思い、下記のようなプログラムを作成しました。 結果として、下記のプログラムはInvalidOperationExceptionを発生し動作しません。 別スレッドからラベルにバインディングしているプロパティを変更したためですが、正しい?(一般的な)解決法がわかりません。 そもそも設計が間違っているという考えも大いにあり得るのですが、その場合、どの様に実装すべきかご教示いただければと思います。 public partial class Form1 : Form { private SampleViewModel svm = new SampleViewModel(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { label1.DataBindings.Add(new Binding("Text", svm.Data, "MyProperty", true, DataSourceUpdateMode.OnPropertyChanged)); } private void button1_Click(object sender, EventArgs e) { // データ更新 svm.Update(); } } internal sealed class SampleViewModel { public SampleModel Data { get { return this._Data; } set { this._Data = value; } } private SampleModel _Data = new SampleModel(); public void Update() { // 重い処理がなかったときは下記の1行だった //Data.MyProperty = DateTime.Now.ToLongTimeString(); // 重い処理をスレッドで処理 // label1にMyPropertyをバインディングしているからInvalidOperationExceptionが発生した Task.Factory.StartNew(() => { // 重い処理ダミー System.Threading.Thread.Sleep(3000); return DateTime.Now.ToLongTimeString(); } ).ContinueWith(task => { Data.MyProperty = task.Result; }); } } // 以下お決まりの実装 internal sealed class SampleModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public string MyProperty { get { return this._MyProperty; } set { this._MyProperty = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("MyProperty")); } } } private string _MyProperty = DateTime.Now.ToLongTimeString(); }
- ベストアンサー
- その他(プログラミング・開発)
- iPhone: PageControlについて
現在、iPhoneのホーム画面風アプリを制作しています。 PageControlとScrollViewを使用して、ページの移動はできるようになりましたが、 以下の問題が発生して困っています。 [問題] ・PageControlで2ページの画面を作っていますが、1ページ目に乗っている「UIButton」は正しく反応するのですが、2ページ目(スライドして表示)の上に乗っている「UIButton」がどうしても反応しません。。。 何か設定が必要なのでしょうか? ***PageControl & ScrollViewのコーディング(一部抜粋)*** (UIButtonの記述等は省略しています) [XXXViewController.h] @interface XXXViewController : UIViewController <UIScrollViewDelegate> { // 画面スクロール用 UIScrollView *scrollView; // PageControl [画面下方の白丸] UIView *pageView; UIPageControl *pageControl; @property (nonatomic, retain) IBOutlet UIScrollView *scrollView; @property (nonatomic, retain) IBOutlet UIView *pageView; @property (nonatomic, retain) IBOutlet UIPageControl *pageControl; [XXXViewController.m] - (void)viewDidLoad { [super viewDidLoad]; scrollView.pagingEnabled = YES; scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 2, scrollView.frame.size.height); scrollView.showsHorizontalScrollIndicator = NO; scrollView.showsVerticalScrollIndicator = NO; scrollView.delegate = self; pageControl.numberOfPages = 2; pageControl.currentPage = 0; pageView.backgroundColor = UIColor.clearColor; [scrollView addSubview:pageView]; } - (IBAction)changePage:(id)sender { CGRect frame = scrollView.frame; frame.origin.x = frame.size.width * pageControl.currentPage; frame.origin.y = 0; [scrollView scrollRectToVisible:frame animated:YES]; } - (void)scrollViewDidScroll:(UIScrollView *)sender { CGFloat pageWidth = scrollView.frame.size.width; pageControl.currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; }
- ベストアンサー
- Mac
- エラーの意味がわかりません
自分のサイトを文法チェックサイトでチェックしました。 http://openlab.ring.gr.jp/k16/htmllint/htmllint.html 意味や修正方法がわからないものがあるので正しい記述方法を教えていただけないでしょうか。↓ 7: line 120: </EMBED> は Mozilla または MSIE 用のタグです。 1: line 72: <A> の属性 `TARGET` はあまり薦められない属性です。 3: line 109: <OBJECT> には等価な内容を書くようにしましょう。 5: line 151: <TABLE> に Mozilla または MSIE 用の属性 `BORDERCOLOR` が指定されています いいサイトがあれば教えてください。よろしくお願いします。
- ベストアンサー
- CSS
- ASP上のVB SCRIPT記述(result setからcountを取得する方法)
初心者です。 ASP上のVB SCRIPT記述(result setからcountを取得する方法)が分かりません。 Set rsRet = MyConn.Execute(strSql) nCltCnt = 0 If Not rsRet Is Nothing Then nCltCnt = rsRet.Count End If という記述をしたのですが、エラーになります。メッセージは以下の通りです。 ●エラー タイプ Microsoft VBScript 実行時エラー (0x800A01B6) オブジェクトでサポートされていないプロパティまたはメソッドです。: 'Count' xxx.asp, line 110 サポートされていないのであれば、result setからの件数の取得を教えて下さい。 どなたかアドバイス宜しく願います。
- ベストアンサー
- Microsoft ASP
お礼
英語サイトを理解するために時間がかかりお礼が遅くなりました。 リンクの紹介をありがとうございました。