Skip to content

Instantly share code, notes, and snippets.

@beatinaniwa
Created July 23, 2012 16:57
Show Gist options
  • Select an option

  • Save beatinaniwa/3164705 to your computer and use it in GitHub Desktop.

Select an option

Save beatinaniwa/3164705 to your computer and use it in GitHub Desktop.
ActionSheet Test
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@viewController = UIViewController.alloc.init
@viewController.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemAction, target:self, action:'tapped:')
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(@viewController)
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
def tapped(sender)
# Failed
actionSheet = UIActionSheet.alloc.initWithTitle("Test", delegate:self, cancelButtonTitle:"Cancel", destructiveButtonTitle:nil, otherButtonTitles:"WRYYY", "View Info")
actionSheet.showInView(@viewController.view)
# Passed
# @actionSheet ||= UIActionSheet.alloc.initWithTitle("Test", delegate:self, cancelButtonTitle:"Cancel", destructiveButtonTitle:nil, otherButtonTitles:"WRYYY", "View Info")
# @actionSheet.showInView(@viewController.view)
end
end
@satococoa
Copy link

よくわかりませんが、謎動作であることだけは確信が持てました。

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @viewController = UIViewController.alloc.init
    @viewController.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemAction, target:self, action:'tapped:')
    @viewController.view.backgroundColor = UIColor.whiteColor
    @window.rootViewController = UINavigationController.alloc.initWithRootViewController(@viewController)
    @window.rootViewController.wantsFullScreenLayout = true
    @window.makeKeyAndVisible
    true
  end

  def tapped(sender)
    actionSheet = UIActionSheet.alloc.initWithTitle("Test", delegate:self, cancelButtonTitle:"Cancel", destructiveButtonTitle:nil, otherButtonTitles:"WRYYY", "View Info")
    p actionSheet # ここをコメントアウトすると落ちる
  end
end

@beatinaniwa
Copy link
Author

サポートチケットを投げたところLaurentから返事をもらいました。許可をもらったのでそのまま転載します。これで解決しました。

The crash sometimes happens because the otherButtonTitles argument is supposed to be a nil-terminated list. If nil is not passed, the method will keep scanning the arguments on the stack.

Changing this line

actionSheet = UIActionSheet.alloc.initWithTitle("Test", delegate:self, cancelButtonTitle:"Cancel", destructiveButtonTitle:nil, otherButtonTitles:"WRYYY", "View Info")

to

actionSheet = UIActionSheet.alloc.initWithTitle("Test", delegate:self, cancelButtonTitle:"Cancel", destructiveButtonTitle:nil, otherButtonTitles:"WRYYY", "View Info", nil)

might fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment