Created
June 24, 2012 02:24
-
-
Save ParkinT/2981108 to your computer and use it in GitHub Desktop.
RubyMotion generic Alert class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A generic class to encapsulate the simple UIAlertView capability in iOS | |
# usage: | |
# @alert = Alert.new { :title => "IMPORTANT ALERT", :message => "It is bad luck to be superstitious!"} | |
# @alert.show | |
class Alert | |
attr_reader :dialog, :alert_message, :alert_title, :alert_acknowledge | |
def initialize(params = {}) | |
@alert_acknowledge = "OK" #default | |
@alert_message = params[:message] if params[:message] | |
@alert_title = params[:title] if params[:title] | |
@alert_acknowledge = params[:ok_text] if params[:ok_text] | |
end | |
def show | |
@dialog ||= UIAlertView.alloc.initWithTitle(@alert_title, message:@alert_message,delegate:nil,cancelButtonTitle:nil,otherButtonTitles:@alert_acknowledge) | |
@dialog.show | |
end | |
def message=(msg) | |
@alert_message = msg | |
end | |
def title=(txt) | |
@alert_title = txt | |
end | |
def message | |
@alert_message ||= "ALERT" | |
end | |
def title | |
@alert_title ||= "Important Message" | |
end | |
def ok_text=(txt) | |
@alert_acknowledge = txt | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment