我試圖實現一個UIActionSheet,它將有一些共享按鈕,以便共享到Twitter,Facebook,電子郵件和打印。單擊UIActionSheet中的按鈕導致我的應用程序崩潰
這裏是我的分享瀏覽或者Controller.h
@interface ShareViewController : UITableViewController <UIActionSheetDelegate, MFMailComposeViewControllerDelegate>
@property (nonatomic, strong) NSMutableDictionary *services;
@property (strong, nonatomic) UIActionSheet *actionSheet;
@property (strong, nonatomic) id <ShareViewControllerDelegate> delegate;
@property (nonatomic, strong) UIPopoverController *popCon;
@property (nonatomic, strong) NSString *serviceTitle;
-(IBAction)loadActionSheet:(id)sender;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
- (void)tweetThis;
- (void)printThis;
- (void)openMail;
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;
@end
這裏是我的分享瀏覽Controller.m或者
-(IBAction)loadActionSheet:(id)sender{
if (self.actionSheet) {
// do nothing
}
else {
UIActionSheet *sharing = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Twitter", @"Facebook", @"Email", @"Print", nil];
[sharing showFromBarButtonItem:sender animated:YES];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"Button index: %d",buttonIndex);
switch (buttonIndex) {
case 0:
[self tweetThis];
break;
case 1:
[self sendToFacebook];
break;
case 2:
NSLog(@"email");
[self openMail];
break;
case 3:
NSLog(@"Print");
[self printThis];
break;
default:
NSLog(@"Error");
break;
}
}
我是個initiaalising在主視圖Controller.m或者我的份額視圖控制器如下:
- (IBAction)shareButtonTapped:(id)sender {
ShareViewController *svc = [[ShareViewController alloc] initWithStyle:UIActionSheetStyleDefault];
[svc loadActionSheet:(id)sender];
}
我可以打開操作表,但是當我點擊任何按鈕時,灰燼的應用程序。任何想法爲什麼?
你能提供崩潰日誌嗎? – Garoal 2012-07-16 20:34:50
你也應該做'self.actionsheet = [[UIActionSheet alloc] init ...];' – jacerate 2012-07-16 20:46:55
jacerate,我補充說,謝謝。但主要問題仍然存在。 – 2012-07-16 20:57:34