In my application i have a nib file (view A) containing some textFields. In front of date textField i have put button pressing which takes to the calendar view. I used the code
-(IBAction)cal:(id)sender
{
CalendarTestViewController *calander1=[[CalendarTestViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:calander1 animated:NO ];
[calander1 release];
}
That is fine.It takes me to calendar view and in calendar view i have wrote the code so that when somebody tap a date it will automatically move to previous view i.e. view A. Then when somebody press a button in A , which takes you confirmation view(another class).It flush all data in textFields.
I was wondering rather then using
[self.navigationController pushViewController:calander1 animated:NO ];
is there any other way to accomplish this behaviour. i want to save my data for confirmation view.
This is my calendar View tap tile method.
- (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile
{
// NSLog(@"Date Selected is %@",[aTile date]);
if (cat==nil) {
cat=[[FormController alloc]initWithNibName:nil bundle:nil];
NSString *st=[[NSString alloc] initWithFormat:@"%@",[aTile date]];
cat.mas=st;
[self.navigationController pushViewController:cat animated:YES];
[cat release];
[self dismissModalViewControllerAnimated:YES];
}
}
after pressing any time from calendar i want to fill date on textField n return to the previous view
I dont want to put this calendar view in navigation stack.
After some changes : below is my CalendarTestViewController.m file’s tap tile method.
- (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile
{
// NSLog(@"Date Selected is %@",[aTile date]);
if (cat==nil) {
cat=[[FormController alloc]initWithNibName:nil bundle:nil];
NSString *st=[[NSString alloc] initWithFormat:@"%@",[aTile date]];
cat.mas=st;
//[self.navigationController pushViewController:cat animated:YES];
//[cat release];
[self dismissModalViewControllerAnimated:YES];
}
}
FormController.m
- (void)calendarDidSelectDate:(NSDate *)selectedDate
{
cali.text=mas;
// set the selectedDate wherever it needs to be...
}
-(IBAction)cal:(id)sender
{
CalendarTestViewController *calendar1=[[CalendarTestViewController alloc]initWithNibName:nil bundle:nil];
calendar1.delegate = self;
[self.navigationController presentModalViewController:calendar1 animated:YES];
}
I have done exactily the same as suggested means protocols and delegate defined same way. no error shown but date is not selected and not filled in label.text in formController
This will bring your calendar view from bottom by default. If you want it to cross-fade you can set:
or you can have it flip by setting:
You need to call this setter before presenting the view controller btw. Also, presenting this calendar view controller modally means you have to dismiss it modally instead of popping it from navigationController.
Edit
To give the selected date back to your FormController, you need to declare a delegate protocol inside your CalendarTestViewController.h
This tells your compiler that the delegate will have to implement method named calendarDidSelectDate:
Then you need to give your CalendarTestViewController a delegate property, also inside .h, right before the last @end
This means you have a property of any class (that’s what id stands for) that conforms to CalendarTestViewControllerDelegate protocol you declared above, and that property is called delegate. In your CalendarTestViewController.m file right under @impelementation line you have to put:
And now in your FormController.h at the line that says
@interface FormController : UITableViewControlleryou need to add<CalendarTestViewControllerDelegate>which tells the compiler this class will conform to that protocol. Now all that’s left to do is in your-(IBAction)cal:(id)sendermethod addcalendar1.delegate = self;and implement the delegate method somewhere inside FormController.mEdit2
You need to replace:
with something like:
and:
with: