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

以下の例外で落ちますね。

2012-07-24 02:09:34.011 ActionSheetAgain[50671:f803] -[IO length]: unrecognized selector sent to instance 0x6ac6d00
2012-07-24 02:09:34.080 ActionSheetAgain[50671:f803] app_delegate.rb:20:in `tapped:': NSInvalidArgumentException: -[IO length]: unrecognized selector sent to instance 0x6ac6d00 (RuntimeError)
2012-07-24 02:09:34.081 ActionSheetAgain[50671:f803] *** Terminating app due to uncaught exception 'RuntimeError', reason: 'app_delegate.rb:20:in `tapped:': NSInvalidArgumentException: -[IO length]: unrecognized selector sent to instance 0x6ac6d00 (RuntimeError)

@satococoa
Copy link

あ、デバッグ分付け足しながら動かしたので行数、ずれてるかもです。

@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