我正在使用 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;
有没有办法做到这一点?