开发者

ios/iphone sdk form management best practices

开发者 https://www.devze.com 2023-03-10 11:38 出处:网络
I\'m working on an iPhone app that will have involve a lot of forms. Currently I have a ViewController class for each settings page which has an UITableView loaded with possible settings. When someone

I'm working on an iPhone app that will have involve a lot of forms. Currently I have a ViewController class for each settings page which has an UITableView loaded with possible settings. When someone clicks on a setting they are taken taken to a new view to enter the form value, or allowed to enter things in place.

What's the best way to keep things DRY? What pieces of this implementation could be implemented once and re-used?

When someone clicks on a settings option which goes to a new view how can I create this view and add a text field according to the data type (uitextfield or picker or something else) in co开发者_如何学编程de?


You can programmatically:

create view hierarchy

UIButton

UILabel

You get the idea.

However, I would recommend getting your logic working for a few of the cases, and then it should become obvious what parts are redundant as you find yourself typing in the same thing over and over. At that point, refactor to get the redundant code into a re-usable form.

HTH.


If you have a tableView, the flow is to create the viewController of the selected settings in the didSelectCell method of your tableView delegate and to push it through the current viewController's navigation controller.

here's a sample:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[self settingsViewControllerAtIndexPath:indexPath] animated:YES];
}

so you'll have to implement the method:

 - (UIViewController*)settingsViewControllerAtIndexPath:(NSIndexPath *)indexPath;

wich will return the viewController managing the settings associated with the selected row of your root tableView.

If your forms are pretty statics, you should consider using a xib in order to minimize the amount of code needed. it isn't a perfect answer to your "how to keep DRY" but it's neat enough ;)

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消