Ill try to explain my situation correctly.
I got 2 views. On my first view i got a table what lists Events. If i touch a cell, I get my EventOverviewView. So i have different behaviors on each view:
FirstView (List of Events):
if I touch and hold on one of the cells i get a UIActionSheet displayed. There I can say that I would like to join that Event, but before the sheet is displayed i get the selected event from an array and save it in a temporary variable. So in that view i don't got any problem. Everything is saved correctly (I see it in my SQLite Browser).
But as I said before, I can say I want to see the Event before i decide if I want to join it, at this point i push to the mentioned EventOverviewView (The event object is set as property and is not nil, I tested it). On this view I can decide too, if I want to join and here we are with my problem (Following methods that handle add a User to event).
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
EventOverviewController *overView;
if (actionSheet == eventUserInvitedSheet) {
//member sheet
switch (buttonIndex) {
case 0:
//join Event clicked //This method is executed and saved correctly in cd!!!
[dccon addAcceptedUserToEvent:tmpEventForActionSheet :appUser];
break;
case 1:
//Decline Event
[dccon removeInvitedUserFromEvent:tmpEventForActionSheet :appUser];
[dccon deleteEvent:tmpEventForActionSheet];
break;
case 2:
//show event
overView = [[EventOverviewController alloc]init];
overView.eventObject = tmpEventForActionSheet;
overView.appUser = appUser;
overView.hidesBottomBarWhenPushed = YES;
[[self navigationController]pushViewController:overView animated:YES];
break;
case 3:
//chat creator
break;
}
totalEvents = [dccon getEvents];
[eventsTable reloadData];
}
}
The method is executed correctly and as u see i push my view on case 2. On the EventOverviewView i got a navbaritem where i execute my sheet on that view:
Create different sheets depends on role of appUser:
- (void)eventOptionSheet{
if ([eventObject.createdBy.userID isEqualToString:appUser.userID]) {
eventCreatorSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete Event"
otherButtonTitles: nil];
eventCreatorSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
[eventCreatorSheet showFromTabBar:self.tabBarController.tabBar];
}else{
NSSet *invitedSet = eventObject.invitedUsers;
NSSet *acceptedSet = eventObject.acceptedUsers;
BOOL existsInInvitedList = [[invitedSet valueForKeyPath:@"objectID"] containsObject:appUser.objectID];
BOOL existsInAcceptedList = [[acceptedSet valueForKeyPath:@"objectID"] containsObject:appUser.objectID];
if (existsInInvitedList) {
eventUserInvitedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Join", @"Decline", @"Chat creator", nil];
eventUserInvitedSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
[eventUserInvitedSheet showFromTabBar:self.tabBarController.tabBar];
}else if (existsInAcceptedList){
eventUserAcceptedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Revoke invite", @"Chat creator", nil];
eventUserAcceptedSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
[eventUserAcceptedSheet showFromTabBar:self.tabBarController.tabBar];
}
}
}
eventObject is the object that i pass from list view
Well let see my sheet actions:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
LastEventsViewController *lastEvents;
if (actionSheet == eventCreatorSheet) {
// creator sheet
switch (buttonIndex) {
case 0:
//Remove Event clicked
[dccon deleteEvent:eventObject];
lastEvents = [[LastEventsViewController alloc]init];
[[self navigationController]popToRootViewControllerAnimated:YES];
break;
}
}
if (actionSheet == eventUserInvitedSheet) {
//member sheet
switch (buttonIndex) {
case 0:
//join Event clicked, logs proves that nothing is nil
NSLog(@"Event test: %@, appUserTest: %@", eventObject.name, appUser.userID);
// same like in first view, but don't save :(
[dccon addAcceptedUserToEvent:eventObject :appUser];
invitedUsers = [NSMutableArray arrayWithArray:[eventObject.invitedUsers allObjects]];
acceptedUsers = [NSMutableArray arrayWithArray:[eventObject.acceptedUsers allObjects]];
[acceptedUserList reloadData];
[invitedUserList reloadData];
break;
case 1:
//Decline Event
[dccon removeInvitedUserFromEvent:eventObject :appUser];
[dccon deleteEvent:eventObject];
lastEvents = [[LastEventsViewController alloc]init];
[[self navigationController]pushViewController:lastEvents animated:YES];
break;
case 2:
//chat creator
break;
}
}
if (actionSheet == eventUserAcceptedSheet) {
//member sheet
switch (buttonIndex) {
case 0:
//leave Event clicked
[dccon removeAcceptedUserFromEvent:eventObject :appUser];
[dccon deleteEvent:eventObject];
lastEvents = [[LastEventsViewController alloc]init];
[[self navigationController]pushViewController:lastEvents animated:YES];
break;
case 1:
//chat creator
break;
}
}
if (actionSheet == changeImageSheet) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.allowsEditing = YES;
switch (buttonIndex) {
case 0:
//Remove user clicked
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePickerController animated:YES];
break;
case 1:
//Show Creator
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
break;
}
}
}
Last but not least the add method:
- (BOOL) addAcceptedUserToEvent:(Event*)event :(User*)invitedUser{
BOOL saved = YES;
[self getDataCoreContext];
if (context) {
[event removeInvitedUsersObject:invitedUser];
[event addAcceptedUsersObject:invitedUser];
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
saved = NO;
}
}
return saved;
}
well i m really confused, why the same method is working on my first view but not on my second. I really hope i could explain it right. ty already for any advice!
EDIT 1: The method that returns, the context and assigning it to a class variable:
@implementation DCConnector{
NSManagedObjectContext *context;
UtilitieHandler *utilitie;
}
- (NSManagedObjectContext *) getDataCoreContext{
/** one line complete init */
CoreDataStack* cdStack = [CoreDataStack coreDataStackWithModelName:@"Model"];
/** one property you need for all Core Data method calls */
if (context == nil) {
context = cdStack.managedObjectContext;
}
return context;
}
EDIT 2: I activated SQLite debugging feature to see if the insert statement is going to core data but like the behavior proves. It works on first but on the second view no insert query is triggers..