Skip to content

Instantly share code, notes, and snippets.

@michaeldv
Created November 1, 2012 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldv/3991657 to your computer and use it in GitHub Desktop.
Save michaeldv/3991657 to your computer and use it in GitHub Desktop.
class Alert
def initialize(title, message, *buttons)
#
# Delegating to self.
#
@alert = UIAlertView.alloc.initWithTitle(title, message:message, delegate:self, cancelButtonTitle:"Cancel", otherButtonTitles:"OK", nil)
@alert.show
self
end
# Never gets called...
def alertView(alertView, clickedButtonAtIndex:buttonIndex)
NSLog "clickedButtonAtIndex(#{buttonIndex})"
end
# Never gets called...
def alertView(alertView, didDismissWithButtonIndex:buttonIndex)
NSLog "didDismissWithButtonIndex(#{buttonIndex})"
end
end
class Alert
def initialize(title, message, *buttons)
#
# Delegating to self.class.
#
@alert = UIAlertView.alloc.initWithTitle(title, message:message, delegate:self.class, cancelButtonTitle:"Cancel", otherButtonTitles:"OK", nil)
@alert.show
self
end
def self.alertView(alertView, clickedButtonAtIndex:buttonIndex)
NSLog "clickedButtonAtIndex(#{buttonIndex})"
end
def self.alertView(alertView, didDismissWithButtonIndex:buttonIndex)
NSLog "didDismissWithButtonIndex(#{buttonIndex})"
end
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
alert = Alert.new("Title", "Message")
NSLog "alert: #{alert.inspect}"
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment