Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Button Class not working with Wax? - Page 2 — Gideros Forum

Button Class not working with Wax?

2»

Comments

  • @Landon, one of the reasons why this would have failed is not including the libraries while building the Gideros player. You need to include the frameworks into your project. I will write a quick article on how to do that (in case)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @OZApps where would I find these libraries?
    JLS
    Lead Coder and Designer
  • you need to add the interfaces to protocolLoader.h and you also need to add the framework libraries (this is the standard way in xCode) ...
    Screen Shot 2012-12-18 at 11.16.36 AM.png
    509 x 597 - 90K
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • ... and if you wait for the article (which I will get around to soon) it will explain all of this.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • Hi @OZApps @bowerandy

    I figured out how to get Twitter AND Facebook to work. It was actually really simple, after looking up what framework I needed to add to the Xcode project.

    I want to know how I would change the type of keyboard that pops up in each textField such as a Dial Pad, A URL Keyboard, etc. But when I try to change it with code I found, it doesn't work. It just shows the regular keyboard.

    Also,I want to know how to get the text from a textfield as such:
    	local textField = UITextField:init()
    	getRootViewController():view():addSubview(textField)
    	local textFrame = BhUIViewFrame.new(textField, CGRect(50,100,150,40))
    	textField:setBackgroundColor(UIColor:colorWithWhite_alpha(0, 0.6))
    	textField:setTextColor(UIColor:colorWithWhite_alpha(1, 1.0))
    	textField:setFont(UIFont:boldSystemFontOfSize(30))
    	textField:layer():setCornerRadius(6)
    	self:addChild(textFrame)
    I want to be able to take the variable in the textField, ex. Username, and make it the text of a String to be able to send it up to a BaaS such as Kinvey: (This may be the code as I am not at my Dev computer)
    username:setText(EVENT LISTENER HERE)
    But I can't seem to find where to find the event listener for textFields is. I keep finding different answers and I don't know which ones work and which ones don't. I see a lot "delegate things" popping up, so I would guess that is what it would be. But I don't know how I would turn that into LUA code because is has "NS" type of code in it.

    Thanks in advance.
    -Landon
    JLS
    Lead Coder and Designer
  • You would set the
    keyboardType
    to
    UIKeyboardTypeNumberPad
    or the relevant one that you want.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • and on the second part of your question, you can use the
    setText
    and
    text
    functions to set/retrieve the text.

    Your eventListener would logically be attached to a button as you will read the textbox when the button is clicked/tapped or are you trying to poll every keypress?
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • ...and lastly, it helps when you are asking a question to share the code where you are stuck. All Objects on the Mac OSX and iOS stem from NSObject (NS stands for Next Step the company that Jobs started when he was ousted from Apple and the same that changed the fate of Apple and Jobs that got him back to Apple)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • bowerandybowerandy Guru
    edited December 2012
    @ljp1203,

    First point. You only need the line:
    getRootViewController():view():addSubview(textField)
    if you are not using a BhUIViewFrame to wrap your text field. If you are using a frame then this will automatically add the UIView to the root view controller for you.

    Next up, there is an example of how to intercept keyboard/text change events in the BhWaxDemo.lua file. Here are the relevant bits:

    First you need to create a "delegate" class to receive event function calls from the text field. I always used be confused by the word delegate but really all it is is a "target" where events from a particular object can go. So, in order to receive UITextView events we have to create a new class in Objective C that obeys the UITextViewDelegate "protocol" (that just means it can receive events from a UITextView).

    Wax provides a function called waxClass() to create classes in ObjectiveC. Just a warning, if you use waxClass() in a Lua file it must either be the only class declaration in the file or must appear at the bottom of the file. So here's the class:
    -- The TextViewDelegate class is an ObjectiveC class that we create to capture
    -- UITextView delegate (notification) messages. This shows the power of Wax; on the
    -- ObjectiveC side it is just like any normal class but, in addition, on the Lua side
    -- it can hold Lua data fields too. In this case we hold a Lua handler function (and target)
    -- that can be used to handle the notifications.
     
    waxClass({"TextViewDelegate", protocols={"UITextViewDelegate"}})	
     
    function TextViewDelegate:textViewDidEndEditing(field)
    	if self.textViewDidEndEditingHandler then
    		self.textViewDidEndEditingHandler(self.handlerTarget, field)
    	end
    end
    Now, in the bit where you create your UITextView, we have to create one of these delegates. Object-oriented people call the process of creating an object, "instantiating". So let's instantiate our delegate and then add some fields to it so it can call one of our own Lua methods to handle the event when the keyboard is put away.
           local textField = UITextField:init()
     
    	-- Let us install a delegate to capture notifications from
    	-- the UITextView. To do this we have to create a helper class, TextViewDelegate,
    	-- which can forward notification calls back to our own handler function.
     
    	local delegate=TextViewDelegate:init()
    	delegate.handlerTarget=self
    	delegate.textViewDidEndEditingHandler=self.onMyTextEdited
    	textField:setDelegate(delegate)
    The delegate is now set up to call the function onMyTextEdited on the object self. This function will be called when the delegate received the message "textViewDidEndEditing". You can find the other potential messages that can be send to UITextViewDelegate in the Apple documentation.

    Finally, you need to provide that function onMyTextEdited in your own code.
    function MyGiderosClass:onMyTextEdited(textView)
        AlertDialog.new("You typed", textView:text(), "OK"):show()
    end
    I hope that helps

    best regards
  • Thanks @bowerandy that does, it works flawlessly!

    Is there a way to make it so that you can only type in so many characters into a textField, until it stops you?

    Ex.
    Usernames can only be 10 characters long. I don't want the user to be able to add more characters then that.

    Thanks.
    -Landon
    JLS
    Lead Coder and Designer
  • @OZApps @bowerandy , I forgot to add, how do I make the textfield input secure like the textfield will only show **** instead of actual characters?

    Thanks.
    -Landon
    JLS
    Lead Coder and Designer
  • @Landon,
    There is no command in the iOS SDK like there is/was in VB where you can set the maxLength and limit the number of characters. In iOS you have to do it yourself on literally every keypress which you can monitor using the
    shouldChangeCharactersInRange
    function

    and to make the textbox a password entry box (asterisk, Asterix would be a Gaul that travels with Obelix carrying Obelisks [Menhir]) you can use the
    setSecureTextEntry
    on the text box set it to true

    :)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @OZApps , thanks with getting my password area secure! Really helped. Now the problem I am having is that I tried your above method to change the Keyboard, but it won't change, it just stays the same.

    Here is the code I used:
    	local textField = UITextField:init()
    	getRootViewController():view():addSubview(textField)
    	local textFrame = BhUIViewFrame.new(textField, CGRect(90,87,190,40))
    	textField:setBackgroundColor(UIColor:colorWithWhite_alpha(0, 0.6))
    	textField:setTextColor(UIColor:colorWithWhite_alpha(1, 1.0))
    	textField:setFont(UIFont:boldSystemFontOfSize(30))
    	textField:setKeyboardType(UIKeyboardTypeNumberPad) <--This doesn't do anything <img class="emoji" src="http://forum.gideros.rocks/resources/emoji/frowning.png" title=":(" alt=":(" height="20" />
    	textField:layer():setCornerRadius(6)
    	self:addChild(textFrame)
    And then is shows this in the console:

    Uploading finished.
    WARNING: No object named 'UIKeyboardTypeNumberPad' found.

    I'm stuck in the water :D

    Thanks again.
    -Landon
    JLS
    Lead Coder and Designer
  • UIKeyboardTypeNumberPad is not an object, but a variable, and it might not be defined,. The value required for that is 4, so you can call it with a 4 instead or define the variable called UIKeyboardTypeNumberPad to 4 and use it.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • ljp1203ljp1203 Member
    edited December 2012
    @OZapps

    Thanks for that, I was really stumped! :D But none of the keyboards aren't showing DONE at the bottom right, they only show return.

    This is my final question hopefully :)

    How do I set the focus on a certain textField, right as the app is opened? And also, I want to add a scrollView to my app because some textFields may be hidden behind the keyboard, and I want to add textfields to the scrollView to allow the user to move the textFields into view. 1st how would I make the scrollview because when I put:
     
    	local scrollView = UIScrollView:init()
    	getRootViewController():view():addSubview(scrollView)
    	local scrollFrame = BhUIViewFrame.new(scrollView, textField2, CGRect(100,100,200,200))
    	self:addChild(scrollFrame)
    the scrollview doesn't come up?

    2nd how would I link the scrollView and textField together to allow the user to move up the textFields?


    Thanks.
    JLS
    Lead Coder and Designer
  • @Landon, I can give you all the answers, but if you want to lean to use iOS, you need to read the apple documentation to understand how things work.

    The text field does not automatically move out of the way (up) when the keyboard is invoked, you have to do that.

    To get the textfield to have the focus, you have to set that as the firstResponder and when you want it not to have focus, you have to set it not to be the first responder (i.e. resign being the first responder)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @OZApps Thanks, that's really good advice. I should look at the documentation rather then ask for all the answers. It would help expand my knowledge of iOS.

    Now I don't think this is a iOS related question, more gideros related. I wanted to add a datePicker to the screen but I don't want it to appear until a button is pressed. I can't seem how to do it. It would be great if you could help me with this, or direct me somewhere that could tell me this.

    Thanks, and Merry Christmas!
    -Landon
    JLS
    Lead Coder and Designer
  • @Landon,
    It works the same as anything else, you can write a function to create and display the datePicker and call this function when the button is pressed, that way you can have it appear on key press only.

    hope that helps and have a happy new year

    cheers,
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • ljp1203ljp1203 Member
    edited January 2013
    @OZAPPS @bowerandy

    Thanks,that helped and was very easy. Before when you told me to make the text field "not a a first responder", I looked it up on stackflow, and they all have me the same answers, but whenever I try to use it, I won't work. I am here is the code :

    - (IBAction)doneEditing:(id)sender {
    [sender resignFirstResponder];
    }

    And this:

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
    [textField resignFirstResponder];
    return YES;
    }

    Is this the correct code and if it is, how would I turn this into usable code?

    Thanks again.
    -Landon
    JLS
    Lead Coder and Designer
Sign In or Register to comment.