Xcode 如何向警报视图按钮添加操作?
我正在尝试设置一个警报视图,这样当按下“Ok”按钮时,一个动作表会显示两个选项。我相信我有正确的格式,没有错误,但当我运行它时,什么也没有发生。请提前帮助并感谢您Xcode 如何向警报视图按钮添加操作?,xcode,ios7,xcode5,uialertview,uiactionsheet,Xcode,Ios7,Xcode5,Uialertview,Uiactionsheet,我正在尝试设置一个警报视图,这样当按下“Ok”按钮时,一个动作表会显示两个选项。我相信我有正确的格式,没有错误,但当我运行它时,什么也没有发生。请提前帮助并感谢您 -(IBAction)sendSG:(id)sender{ UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Send Study Guides!"
-(IBAction)sendSG:(id)sender{
UIAlertView *message = [[UIAlertView alloc]
initWithTitle:@"Send Study Guides!"
message:@"Please send your study guides to help create a bigger and more efficent network of study guides. You can send them by email, or you can take a picture of your study guide and send it to us."
delegate:self //Changed Here
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[message show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
UIActionSheet *sendOptions = [[UIActionSheet alloc]
initWithTitle:@"Add study guide"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Destructive Button"
otherButtonTitles:@"Email", @"Take a picture", nil];
[sendOptions showInView:self.view];
}
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSString *emailTitle = @"Study Guides";
NSArray *toRecipents = [NSArray arrayWithObject:@"blank@gmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
[mc setSubject:emailTitle];
[mc setToRecipients:toRecipents];
[self presentViewController:mc animated:YES completion:NULL];
}
}
你的按钮索引搞错了。
按钮
buttonIndex==0
是取消按钮,buttonIndex==1
是确定按钮。在警报视图的回调中尝试以下操作:
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// show action sheet here.
});
如果它对您有效,请根据需要修改delayUnseconds
其他一切都会好的。。如果有任何问题,请告诉我是的,很抱歉回复太晚,但这很有效!非常感谢你的帮助!