I have a button in one of my classes that i create it with xcode/interface builder and I want to connect my button to another class that it create an event based calendar,
I want to press my button but after that it will automatically create another page and inside of that page there is another button –> that when I push that button I can access to the event based calendar page,my question is
how can I remove the second page
here is code that generate second and third pages
AddEvent.h
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
@interface AddEvent : UIViewController <UINavigationBarDelegate, UITableViewDelegate,
EKEventEditViewDelegate, UINavigationControllerDelegate, UIActionSheetDelegate> {
EKEventViewController *detailViewController;
EKEventStore *eventStore;
EKCalendar *defaultCalendar;
NSMutableArray *eventsList;
}
@property (nonatomic, retain) EKEventStore *eventStore;
@property (nonatomic, retain) EKCalendar *defaultCalendar;
@property (nonatomic, retain) NSMutableArray *eventsList;
@property (nonatomic, retain) EKEventViewController *detailViewController;
- (NSArray *) fetchEventsForToday;
@end
AddEvent.m
#import "AddEvent.h"
@interface AddEvent ()
@end
@implementation AddEvent
@synthesize eventsList, eventStore, defaultCalendar, detailViewController;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
Here is the code that create the second screen
self.title = @"Events List";
// Initialize an event store object with the init method. Initilize the array for events.
self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];
// Get the default calendar from store.
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
// Create an Add button
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemAdd target:self action:@selector(addEvent:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
self.navigationController.delegate = self;
// Fetch today's event on selected calendar and put them into the eventsList array
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];
}
// Allow event editing.
detailViewController.allowsEditing = YES;
// Push detailViewController onto the navigation controller stack
// If the underlying event gets deleted, detailViewController will remove itself from
// the stack and clear its event property.
[self.navigationController pushViewController:detailViewController animated:YES];
}
#pragma mark -
#pragma mark Add a new event
// If event is nil, a new event is created and added to the specified event store. New events are
// added to the default calendar. An exception is raised if set to an event that is not in the
// specified event store.
- (void)addEvent:(id)sender {
// When add button is pushed, create an EKEventEditViewController to display the event.
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
// set the addController's event store to the current event store.
addController.eventStore = self.eventStore;
// present EventsAddViewController as a modal view controller
[self presentModalViewController:addController animated:YES];
addController.editViewDelegate = self;
}
and also I don’t know how should I connect my button in first screen to the third page and remove the second screen
Thanks in advance!
In your first viewcontrollers’s viewDidLoad add the following UIBarButtonItem code for plus button
self.navigationItem.rightBarButtonItem = addButtonItem;
and also add the action code
then add necessary code for adding events in EKEventEditViewController’s viewDidLoad.