-1

I know that there already are lots of questions and even useful answers concerning this question on the web. I tried to add a calendar event to the iPhone calendar from inside my application. I used this code, which actually worked:

EKEventStore *es = [[EKEventStore alloc] init];
EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
controller.eventStore = es;
controller.editViewDelegate = self;
[self presentModalViewController:controller animated:YES];

The only thing was that I could not release the calendar controller, which is because I should have said:

[Controller release]

or something But my main.m is set to autorelease:

int main(int argc, char *argv[])
{
    @autoreleasepool {
          return UIApplicationMain(argc, argv, nil, NSStringFromClass([...AppDelegate class]));
    }   
}

and if I manually release I get an error, do I have to change something in the main.m?

Cezar
  • 55,636
  • 19
  • 86
  • 87
Enno B.
  • 1
  • 3

2 Answers2

0

As I understand from the comments, it might be you are using ARC. In order to check that, go on your project tab, select Build Settings and type in the search bar

Automatic Reference Counting

If it's set to you YES, you don't need to release the object.

EDIT

It looks like there have been a misunderstanding regarding the word release. Release as you mentioned it (calling release on an object) means to decrease the object reference counter.
Dismissing a modal view controller is a complete different thing. In order to do that, on the cancel button delegate method, you have to invoke:

[yourViewControllerInstance dismissModalViewControllerAnimated:YES];

That's the method you are searching for.

Nicola Miotto
  • 3,647
  • 2
  • 29
  • 43
  • it is and I did not realease the controller: But when I run my app in the simulator I can't press done or cancel, at leatst nothing happens – Enno B. Aug 10 '13 at 09:59
  • Ahh that you meant with "release": dismissing the modal view controller? Not release the memory object, right? – Nicola Miotto Aug 10 '13 at 10:02
0

In your target's build settings, if you see Objective-C Automatic Reference Counting then you are using ARC:

enter image description here

And if you are using ARC then you are not responsible to release object by your self.

I strongly recommend to read more about ARC, you can start from here, this is the most important thing you should consider if you want to build a real application.

Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68