I have a UIActionSheet implemented into my code. It's setup with Email and Facebook as the two other buttons, and they both work fine. However, with cancel, sometimes it will work right away, sometimes it won't work at all, and sometimes it takes it a minute before it will work. Here is the code I am using for the ActionSheet:
Code:
-(IBAction)action:(id)sender {
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Share article with a friend..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Email", @"Facebook", nil];
[popup showInView:[self view]];
[popup release];
}
- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
{self.currentURL = links.request.URL.absoluteString;
self.title = [links stringByEvaluatingJavaScriptFromString:@"document.title"];
// This sample can run on devices running iPhone OS 2.0 or later
// The MFMailComposeViewController class is only available in iPhone OS 3.0 or later.
// So, we must verify the existence of the above class and provide a workaround for devices running
// earlier versions of the iPhone OS.
// We display an email composition interface if MFMailComposeViewController exists and the device can send emails.
// We launch the Mail application on the device, otherwise.
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}
break;
case 1:
{self.currentURL = links.request.URL.absoluteString;
self.title = [links stringByEvaluatingJavaScriptFromString:@"document.title"];
_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
[self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
}
break;
}
}