Skip to content

Instantly share code, notes, and snippets.

@ParkinT
Created June 24, 2012 02:24
Show Gist options
  • Save ParkinT/2981108 to your computer and use it in GitHub Desktop.
Save ParkinT/2981108 to your computer and use it in GitHub Desktop.
RubyMotion generic Alert class
# 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