Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用UIActionSheet响应程序_Ios_Objective C_Cocoa Touch_Uiactionsheet_Uiactionsheetdelegate - Fatal编程技术网

Ios 未调用UIActionSheet响应程序

Ios 未调用UIActionSheet响应程序,ios,objective-c,cocoa-touch,uiactionsheet,uiactionsheetdelegate,Ios,Objective C,Cocoa Touch,Uiactionsheet,Uiactionsheetdelegate,这是我在stackoverflow上的第一篇文章,如果我犯了一些错误,请原谅我 我是一个相对较新的应用程序设计师,我一直在开发一个新的应用程序,我希望很快发布。我最近遇到了一个问题。我无法使用UIActionSheet。虽然显示良好,但按钮只会使操作表消失。我试了很多东西都没有用;我做了中建议的一切(由具有类似但不完全相同问题的人制作)。我已经使用NSLog测试并确保没有完全调用该函数。我已经尝试过更改showInView,尽管这似乎不会产生任何影响。总之,这是我目前的代码: - (void)m

这是我在stackoverflow上的第一篇文章,如果我犯了一些错误,请原谅我

我是一个相对较新的应用程序设计师,我一直在开发一个新的应用程序,我希望很快发布。我最近遇到了一个问题。我无法使用
UIActionSheet
。虽然显示良好,但按钮只会使操作表消失。我试了很多东西都没有用;我做了中建议的一切(由具有类似但不完全相同问题的人制作)。我已经使用
NSLog
测试并确保没有完全调用该函数。我已经尝试过更改
showInView
,尽管这似乎不会产生任何影响。总之,这是我目前的代码:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if ( event.subtype == UIEventSubtypeMotionShake )
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"You Shook?" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"End Game" otherButtonTitles:@"Settings", nil];
        [actionSheet showInView:self.view];
    }

    if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
        [super motionEnded:motion withEvent:event];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        UIAlertView *endGameAlertView = [[UIAlertView alloc] initWithTitle:@"End Game" message:@"Are you sure you want to end the current game?" delegate:nil cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [endGameAlertView show];

    }

    else
    {
        UIAlertView *unimplementedSettingsAlertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"This feature is not yet implemented" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [unimplementedSettingsAlertView show];
    }
}
正如您所看到的,操作表是通过摇晃设备触发的(该设备工作正常),同样,唯一的问题是按钮除了关闭操作表之外什么都不做。我正在OSX 10.9.1上使用Xcode 5.0.2。如果我遗漏了任何重要信息,请告诉我。提前谢谢你


~Junior

将代理设置为self

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"You Shook?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"End Game" otherButtonTitles:@"Settings", nil];

当前,您正在将
actionSheet
delegate
设置为
nil
,因此不会调用您的delegate方法

在ViewController.h文件中,按如下方式编写:

@interface ViewController : UIViewController <UIActionSheetDelegate>

当我这样做的时候,我得到了这个错误:
将'ViewController*const\u strong'发送到不兼容类型'id'的参数
在你必须显示的标题中,这个UIViewController子类实现了UIActionSheetDelegate接口,如下所示:YourViewController:UIViewController好的,错误现在消失了,谢谢!然而,当我尝试运行它时,我得到了以下错误:
clang:error:linker命令失败,退出代码为1(使用-v查看调用)
您必须获得一些错误日志。此错误日志是否提到任何重复符号或未找到文件错误??是:ld:3架构I386的重复符号好的,明白了!我不小心将
#include AppDelegate.m
添加到了我的ViewController.m中。现在一切都很顺利。非常感谢。
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"You Shook?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"End Game" otherButtonTitles:@"Settings", nil];