about delete EKEvent, when action = EKEventEditViewDelegate - iphone

- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;
case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
// and reload table view.
// If the new event is being added to the default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList addObject:thisEvent];
}
[controller.eventStore saveEvent:controller.event span:EKSpanFutureEvents error:&error];
[self.tableView reloadData];
break;
case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
// and reload table view.
// If deleting an event from the currenly default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
[controller.eventStore removeEvent:thisEvent span:EKSpanFutureEvents error:&error];
[self.tableView reloadData];
break;
default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
}
this function in the EKEventEditViewDelegate. I want to know when i click which button the "action" value is EKEventEditViewActionDeleted.
at first, I think when I click the delete event button, the action == EKEventEditViewActionDeleted. but not. anyone can help me?

Implement the EKEventViewDelegate protocol then check for the delete event with...
-(void) eventViewController:(EKEventViewController *)controller didCompleteWithAction:(EKEventViewAction)action
{
if (action == EKEventViewActionDeleted) {
// Update unique event ID to core data & change text of button to new
_itemReminder = NULL;
_part.reminderID = NULL;
_savedEventFound = NO;
[_reminderButton setTitle: #"New" forState: UIControlStateNormal];
}
}

Related

Be notified when a UITableViewCell swipe delete is cancelled in iOS 7

I'm using willTransitionToState which notifies me when the right hand delete button is shown. However, this method is not called when the delete is cancelled by tapping outside the cell area. I've also tried tableView:didEndEditingRowAtIndexPath.
The answers found in this question don't work in iOS 7.
The following code works for iOS 7 (not for iOS 6). The iOS 6 solution is this.
- (void)layoutSubviews
{
[super layoutSubviews];
[self detectDeleteButtonState];
// it takes some time for delete button to disappear
[self performSelector:#selector(detectDeleteButtonState) withObject:self afterDelay:1.0];
}
- (void)detectDeleteButtonState
{
BOOL isDeleteButtonPresent = [self isDeleteButtonPresent:self.subviews];
if (isDeleteButtonPresent) {
NSLog(#"delete button is shown");
} else {
NSLog(#"delete button is gone");
}
}
-(BOOL)isDeleteButtonPresent:(NSArray*)subviews
{
for (UIView *subview in subviews)
{
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellDeleteConfirmationView"])
{
return [subview isHidden] == NO;
}
if([subview.subviews count] > 0){
return [self isDeleteButtonPresent:subview.subviews];
}
}
return NO;
}

Alert View Click not calling instantly like iOS 6 in iOS 7

In my application while user go to the next view controller I am showing indicator with cancel button. On cancel button click i m setting value -2 for one variable like appDel.Val = -2; And before push to next controller i m checking that if appDel.Val = -2; then return. So no need further process.
this is working fine with iOS6 devices. When user tap on cancel in UIAlertView Delegate method for Alert click calls immediately and value set for appDel.Val=-2. So it will return without any further process.
Bit With iOS7 it creating issue like when user tap on cancel in alert, alertview delegate method is calling after completing current process for push view controller. So appDel.Val=-2 will be set after push controller from alert click method as alert delegate method is not calling immediately same like iOS 6
Can any one please suggest, How can i fix this for iOS 7?
Here is my code.
-(void)goToNextViewController:(NSDictionary*)outputDictionary
{
myViewController *mtvc=[appDel.myDict valueForKey:[outputDictionary valueForKey:#"id"]];
if (mtvc) {
[appDel showindicator:#"Please Wait..."];
}else{
[appDel showindicator:#"Connecting..."];
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
self.rootDict = [[NSMutableDictionary alloc] initWithDictionary:outputDictionary];
appDel.activeId = [outputDictionary valueForKey:#"id"];
if(!mtvc)
{
myViewController *mtvc = [[myViewController alloc]initWithNibName:#"myViewController" bundle:nil];
appDel.tempViewController=mtvc;
appDel.tempViewController.isVeryFirst = YES;
[mtvc release];
}
else
{
appDel.tempViewController=mtvc;
appDel.tempViewController.isVeryFirst = NO;
#try {
[self.navigationController pushViewController: mtvc animated: YES];
}
#catch (NSException * e) {
NSLog(#"Exception: %#", e);
}
[appDel performDismiss];
return;
}
if (appDel.Val==-2)
{
[appDel.newConnections removeObjectForKey:appDel.activeId];
appDel.tempViewController.isNewConnection = NO;
appDel.Val = 0;
[appDel performDismiss];
return;
}
[appDel.newConnections setObject:appDel.tempViewController forKey:[outputDictionary valueForKey:#"id"]];
[self.navigationController pushViewController: appDel.tempViewController animated: YES];
[appDel performDismiss];
}
Alert click
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alert.tag==654)
{
self.Val = -2;
[baseAlert dismissWithClickedButtonIndex:0 animated:YES];
baseAlert=nil;
}
}
Thanks for any help.

EKEditviewController keeps showing the title in the navigationbar

I'm working with the EventKit Framework. It is working almost perfect but I have still some issues. When I push my on an Event, it goes to the details of that Event. It shows correctly the details and I can also edit and save it. The problem is with the navigation bar.
It shows the titles inside the navigation bar.These titles are Event Details and Edit. Also it is not showing a backbutton, to go back to my calendar. What I also should mention is that I'm using the Kal Calendar framework.
I'm pushing to de detailsViewController like this.
Appointment *appointment = [dataSource appointmentAtIndexPath:indexPath];
// Upon selecting an event, create an EKEventViewController to display the event.
self.detailViewController = [[EKEventViewController alloc] initWithNibName:nil bundle:nil];
self.detailViewController.title = #"";
detailViewController.event = appointment.event;
// Allow event editing.
detailViewController.allowsEditing = YES;
[calendar.navigationController pushViewController:detailViewController animated:YES];
And this is how my delegate looks like
// Overriding EKEventEditViewDelegate method to update event store according to user actions.
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
controller.title = #"";
switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;
case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
// and reload table view.
// If the new event is being added to the default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList addObject:thisEvent];
}
[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
//[calendar reloadData];
break;
case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
// and reload table view.
// If deleting an event from the currenly default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
//[calendar reloadData];
break;
default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
}
// Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar.
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller {
EKCalendar *calendarForEdit = self.defaultCalendar;
return calendarForEdit;
}
I came up with this solution:
EKEventEditViewController * controller = [[EKEventEditViewController alloc] init];
controller.eventStore = self.eventStore;
controller.event = result;
controller.title = #"";
controller.navigationItem.title = #"";
controller.navigationItem.titleView = [UIView new];
NSArray * array =controller.navigationBar.items;
UINavigationItem * titleItem = array.firstObject;
titleItem.title = #"";
controller.editViewDelegate = (id)self;
[self presentViewController:controller animated:YES completion:NULL];
The EKEventEditViewController is not embedded in a navigation controller, it has its own UINavigationBar, I keep the navigation item if Apple will change this in the future and embed it in a navigation controller.
i think you have added navigation item on the storyboard or nib file. remove it.
make self.title=nil; or self.title=#"";

sms window will not close after sending or cancelling sms

- (IBAction)SendTxt:(id)sender {
MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc] init];
[textComposer setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
[textComposer setRecipients:[NSArray arrayWithObjects:#"123456",#"123456", nil]];
[textComposer setBody:#"HELP ME"];
[self presentViewController:textComposer animated:YES completion:NO];
}
else {
NSLog(#"Can't open Text");
}
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultSent:
NSLog(#"SENT");
break;
case MessageComposeResultFailed:
NSLog(#"FAILED");
break;
case MessageComposeResultCancelled:
NSLog(#"CANCELLED");
break;
default:
break;
}
}
I have the above code which brings up the sms window as normal..
It works ok and sends a SMS but the SMS window will not close after sending or cancelling..
The NSLog registers the send or cancel but the SMS window will not go away!
Can anyone help?
Thanks
Mat
You have to dismiss it yourself using
[self dismissViewControllerAnimated:YES completion:^{ // something to do on completion if you need}];

UIAlertView, present modally for UIAlertViewStyleSecureTextInput

So I want to present to the user an alert view for them to enter the password. I'd like to check to make sure that something was entered at the keyboard. I know in the UIAlertViewDelegate, you can get the text input. However, the only solution I have so far is,
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(#"buttonIndex: %i", buttonIndex);
if (buttonIndex == 0) {
UITextField *passwordTextField = [alertView textFieldAtIndex:0];
if (!passwordTextField.text.length == 0) {
NSLog(#"password: %#", passwordTextField.text);
// save the password
}
else {
// Show the alert view again asking for the password
}
}
}
where I would ask for the password again right after they click ok if they didn't enter anything. Is there a better solution to this? Thanks!
Present the alert view again. You can put the alert view in a method and call it.
...
} else {
[self showPassAlert];
}
You can also watch for when the text field is edited, and enable/disable the button in the alert view. If the text field's length is 0, disable the button. When the text field is edited and its length is greater than 0, enable the button. This is more graceful than closing and reopening the view.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(textDidChange) name:UITextFieldTextDidChangeNotification object:textField];
...
-(void)textDidChange {
for (UIView *view in alertView.subviews) {
if ([view isKindOfClass:[UIButton class]]) {
if (textField.text.length == 0) {
//you may need to look for the button's title to make sure you are not disabling the cancel button
((UIButton *) view).enabled = NO;
} else {
((UIButton *) view).enabled = YES;
}
}
}
}
Why don't you create iboutlet/reference for your UITextFields, which will aid you to retrieve its value at any moment of time.