开发者

Objective-C Base class for view and text field

So I'm developing a program where there are multiple little program inside. The main window show all the mini program, for the moment there is only one working but they will all be somewhat similar, so i click on the 'TimeEntry' button wich brings me to another view controller that way:

(IBAction)btnTe_clicked:(id)sender 
{

TELogin *ViewTELogin = [[TELogin alloc] init];


ViewTELogin.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;


[self presentModalViewController:ViewTELogin animated:YES];

[ViewTELogin release];

}

and then enter some data, validate and go to the next view controller, if i want to go back i use:

- (IBAction)btnMenu_clicked:(id)sender

{

[[self parentViewController] dismissModalViewControllerAnimated:YES];

}

so far so good, the mini app works, but the code is ugly, in each view controller I have to set a Scroll View, some constant and UITextField method like that to prevent a text field to be hidden by the keyboard:

-(void)textFieldDidEndEditing:(UITextField *)textField
{

CGRect viewFrame =self.view.frame;
viewFrame.origin.y += animatedDistance; //anima开发者_运维技巧ted distance is a CGFloat
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];

}

And I'm pretty sure it's possible to make one Base class which implements the scroll view and textfield delegate and then for each view controller i would just have to import the base class and design my interface. But everything i tried so far was just a waste of time that's why i'm calling for help.


Are you familiar with the MVC documentation?

If not, try making your own View class and Model class. The model class would hold your data and maybe other properties (depending on your design) and the View class would hold the UITextField and any other views already inside the ViewController.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜