Database Reference
In-Depth Information
Inside the
configureView
method we start off by setting the text property of our text fields to the
appropriate values. Next we set the
inputView
and
InputAccessoryView
of
txtBirthday
by calling
two new methods that we will set up shortly. Then we use quartz core to add a border to the image
view. Finally we determine whether our image is set on our object. If so, we create the
UIImage
from
the
NSData
property image or we assign the image asset
ImgNoImage
.
Let's add those to input methods now:
-(UIDatePicker *)setupDatePickerWithDate:(NSDate *)date {
if(date == nil)
date = [NSDate date];
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
[datePicker setDatePickerMode:UIDatePickerModeDate];
[datePicker setDate:date];
[datePicker addTarget:self action:@selector(birthdayValueChanged:)
forControlEvents:UIControlEventValueChanged];
return datePicker;
}
-(UIView *)setupKeyboardAccessoryView {
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.
bounds), 44)];
UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered target:self action:@selector(btnDatePickerDonePressed:)];
[toolbar setItems:@[btnDone]];
return toolbar;
}
In the first method
setupDatePickerWithDate:
we first check to see whether we received a date.
If we didn't, we set the date to today's date by calling the class method
[NSDate date];
. Next
we allocate and initialize our date picker. We set the
datePickerMode
to
UIDatePickerModeDate
.
This sets it so that the user is only allowed to pick a data and not a time. We then pass the date
to the picker so that when the users see the date picker they are either on the current date in the
birthday field or they are on the current date. Next we add a target to the
datePicker
for the event
UIControlEventValueChanged
. This causes the
birthdayValueChanged
: method to be fired every time
the value of the picker is changed. Then we return this
datePicker
so that it can be used.
In the second method, we create a
UIToolbar
that is the view's width, but only 44 points high. Then
we create a
UIBarButtonItem
and give it a target of
btnDatePickerDonePressed:
. Finally we call
setItems:
on the toolbar and pass it an array containing the Done button.
The
birthdayValueChanged:
method is self-explanatory and should look like this.
-(void)birthdayValueChanged:(UIDatePicker *)datePicker {
_txtBirthday.text = [_dateFormatter stringFromDate:[datePicker date]];
}
Search WWH ::
Custom Search