1

QuickDialog と Reactive Cocoa を使用してかなり長いフォームを作成しています。同じフォームから QElements をセットアップするファクトリ メソッドを記述できるようになりたいと考えています。

これが私が今やっている方法の例です。

self.root = [[QRootElement alloc] init];
self.root.title = self.title;
self.root.grouped = YES;

self.basic = [[QSection alloc] init];
self.basic.title = @"Basic Information";
[self.root addSection:self.basic];

QEntryElement *address = [[QEntryElement alloc] init];
address.title = @"Address";
RAC(address, textValue) = [RACObserve(self, viewModel.address) distinctUntilChanged];
RAC(self, viewModel.address) = [RACObserve(address, textValue) distinctUntilChanged];
[self.basic addElement:address];

QEntryElement *city = [[QEntryElement alloc] init];
city.title = @"City";
RAC(city, textValue) = [RACObserve(self, viewModel.city) distinctUntilChanged];
RAC(self, viewModel.city) = [RACObserve(city, textValue) distinctUntilChanged];
[self.basic addElement:city];

QEntryElement *state = [[QEntryElement alloc] init];
state.title = @"State";
RAC(state, textValue) = [RACObserve(self, viewModel.state) distinctUntilChanged];
RAC(self, viewModel.state) = [RACObserve(state, textValue) distinctUntilChanged];
[self.basic addElement:state];

QEntryElement *postal = [[QEntryElement alloc] init];
postal.title = @"Zip";
RAC(postal, textValue) = [RACObserve(self, viewModel.postalCode) distinctUntilChanged];
RAC(self, viewModel.postalCode) = [RACObserve(postal, textValue) distinctUntilChanged];
[self.basic addElement:postal];

QEntryElement *phone = [[QEntryElement alloc] init];
phone.title = @"Phone";
RAC(phone, textValue) = [RACObserve(self, viewModel.phoneNumber) distinctUntilChanged];
RAC(self, viewModel.phoneNumber) = [RACObserve(phone, textValue) distinctUntilChanged];
[self.basic addElement:phone];

次のようなメソッドを呼び出せるようにしたいと思います。

-(QEntryElement *)racEntryElementWithTitle:(NSString *)title andModel(ViewModel *)model andProperty:(NSString*)property;

これを行う方法はありますか?

4

2 に答える 2

0

あなたが間違いなく直面している問題は、それらのマクロです。これに対する 1 つのアプローチは、プリプロセッサを実行して、マクロの出力がどのように見えるかを確認することです。

たとえば、次の行です。

RAC(postal, textValue) = [RACObserve(self, viewModel.postalCode) distinctUntilChanged];

以下に展開します。

[[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:(postal) nilValue:(((void *)0))][@(((void)(__objc_no && ((void) postal. textValue, __objc_no)), "textValue"))] = [[(id)(self) rac_valuesForKeyPath:@(((void)(__objc_no && ((void)self.viewModel.postalCode, __objc_no)), "viewModel.postalCode")) observer:self] distinctUntilChanged];

これにより、必要なパーツをパラメーター化できるようになります。

于 2014-05-25T13:02:39.520 に答える