iOS :
I have app that open some content and i have added button on a right Navigation bar that can delete message content from saved catch, Now i want to put conformation action that conform with user before deleting message,
I have created UIActionsheet like this:
sheet = [[UIActionSheet alloc] initWithTitle:@"Delete Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Message" otherButtonTitles:nil];
// view sheet
[sheet showInView:self.view];
NSLog(@"Button %d", buttonIndex);
Now how can i use this value in my deleteContent function?
My delete function is
-(void) deleteContent
{
if (buttonIndex=0)
{
[[NSFileManager defaultManager] removeItemAtPath:fileName error:&e];
}
}
My question is how can i rearrange this in just one function that can be called in one call and does all of this.
That’s not the way to do it. Call a function from the button in your nav bar to present the action sheet. Then implement the UIActionSheetDelegate method actionSheetDidDismissWithButtonIdex to take car of your actual deletion.
EDIT: If you need to pass the identity of the item to delete from the method that causes the action sheet to be presented, just add a parameter to you presentActionSheet method and pass the item.