@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)
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:
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.
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?
...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)
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)endend
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
@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
@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.
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.
Thanks for that, I was really stumped! 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:
@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)
@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.
@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.
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 :
Comments
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
Lead Coder and Designer
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
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
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:
Thanks in advance.
-Landon
Lead Coder and Designer
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
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?
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
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
First point. You only need the line:
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:
Finally, you need to provide that function onMyTextEdited in your own code.
best regards
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
Lead Coder and Designer
Thanks.
-Landon
Lead Coder and Designer
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
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
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
Here is the code I used:
Uploading finished.
WARNING: No object named 'UIKeyboardTypeNumberPad' found.
I'm stuck in the water
Thanks again.
-Landon
Lead Coder and Designer
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
Thanks for that, I was really stumped! 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:
2nd how would I link the scrollView and textField together to allow the user to move up the textFields?
Thanks.
Lead Coder and Designer
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)
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
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
Lead Coder and Designer
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,
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
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
Lead Coder and Designer