GLBasic forum

Main forum => GLBasic - en => Topic started by: DaCarSoft on 2011-Feb-18

Title: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: DaCarSoft on 2011-Feb-18
Hello!

After the reading of several posts in this forums, I found that many people were searching (like me) a way to obtain data using the native iOS keyboard   :S

I was trying the untested code from Trucidare (http://pastebin.com/vLcTxCX5), but it didn't work "as is" for me   :'(

As I need a way for the user to input data (usernames mostly), I was trying and thinking harder to obtain the correct source code to show an alert box on screen, expand the native iOS keyboard and wait for the user input.

And the good news are: It works!!!!   but there are also bad news: The working is not totally OK.

Its to say: I can't obtain a string longer than 8 characters (the string appears corrupt if the user input is longer) and I can't show Spanish characters like "á" or "Ñ" in the alert messages or titles...

I'm not a newbie in programming but I'm a newbie in XCode and GLBasic, and I remember only a bit of C/C++.

Someone could help???  Gernot???  Trucidare???    =D    It is near of completion...     :P

This is the code:

in the XCode project I added the next lines to a .mm file:
Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)
#import <UIKit/UIAlert.h>



@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
UITextField* txtValue;
const char* resString;
const char* resButton;
}
- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabel:(NSString*)pLabel;
- (const char*)getValue;
@end

@implementation GLBasicMessageBoxer

- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabel:(NSString*)pLabel
{
UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Yes"];

//[alert addTextFieldWithValue:@"" label:@"T1"];    ---> This do not pass the App Store review because it is undocumented
//[alert addTextFieldWithValue:@"" label:@"T2"];    ---> This do not pass the App Store review because it is undocumented
//txtValue = [alert textFieldAtIndex:0];   

txtValue = [[UITextField alloc] init];
txtValue.frame = CGRectMake(12.0, 70.0, 260.0, 25.0);
txtValue.placeholder = pLabel;
txtValue.backgroundColor = [UIColor whiteColor];
txtValue.clearButtonMode = UITextFieldViewModeWhileEditing;
txtValue.keyboardType = UIKeyboardTypeAlphabet;
txtValue.keyboardAppearance = UIKeyboardAppearanceAlert;
txtValue.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtValue.autocorrectionType = UITextAutocorrectionTypeNo;
[txtValue becomeFirstResponder];

[alert addSubview:txtValue];

[alert show];
//[alert release];
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch(buttonIndex)
{         
case 0:
break;         
case 1:
resButton = "1";
resString = [txtValue.text UTF8String];
break;     
}
}

- (const char*)getValue
{
if (resButton == "1"){
return resString;
}
else
{
return "";
}
}

@end

GLBasicMessageBoxer* newAlert;

extern "C" void iOSMessageBox(const char* pTitle, const char* pMessage, const char* pLabel)
{
newAlert = [[GLBasicMessageBoxer alloc]init];
[newAlert showAlert:[NSString stringWithUTF8String:pTitle] andMessage:[NSString stringWithUTF8String:pMessage] andLabel:[NSString stringWithUTF8String:pLabel]];
}

extern "C" const char* GetiOSMessageBoxValues()
{
return [newAlert getValue];
}



#endif


and from GLBasic I can use this code:
Code (glbasic) Select

IMPORT "C" void iOSMessageBox(const char*,const char*, const char*)

IMPORT "C" const char* GetiOSMessageBoxValues()

iOSMessageBox("Title12345678","Text12345678" + CHR$(0xD) + CHR$(0xD), "Example")

GLOBAL MESSAGE$

WHILE MESSAGE$ = ""
SLEEP 500
MESSAGE$ = GetiOSMessageBoxValues()
WEND

PRINT MESSAGE$, 100, 100
SHOWSCREEN


My next steps would be to convert in parameters the number of buttons, text of each button, number of text boxes, content of the label of each text box... to return the index of the button pressed...   but before I need to obtain the correct string from the UITextField and use characters of languages different than english (may be some thing related to the UTF8/ASCII format or may be that I have to use roman codepages...)  :rant:

Any ideas???

Thanks in advance, hope this helps someone!
Title: Re: Keyboard "InputBox" for iOS
Post by: Moebius on 2011-Feb-18
Although I can't get my head around objective C well enough to make contributions to the code, I can offer conceptual ideas.

In your simple sample program, it simply loops until the string isn't blank.  There are two problems with this - if the user enters nothing, or if they press 'cancel' in the alert (assuming there is that button), the program will 'hang'.  There needs to be a way of determining if the string has been entered, because you can't rely on the string NOT being blank to determine if the alert has been closed.

Perhaps something like this:  isMsgBoxOpen() that returns true or false?

One thing that would be useful is if you had:
       GetiOSMessageBoxValues()
       GetiOSMessageBoxValuesAsync()

In one function, it loops and waits until the user has closed the alert, and in the other it just returns the current text that has been entered.


Anyway, thanks a lot for putting this together  :good:  and I'm sorry that the only thing I can do is complicate things with ideas for functions  :whistle:
Title: Re: Keyboard "InputBox" for iOS
Post by: DaCarSoft on 2011-Feb-18
Its nothing!
And, yes, as you say, the program loops until the string is not blank, and don't take care of "cancel" button control...

This code is a sample, that need some fixes to obtain a correct and "complete" string, that is my priority :)

I have several plans for the GetiOSMessageBoxValues(), like, for example, to include parameters in the function, may be doing something like this:

iOSMessageBoxValues("Title", "Message", "LabelAtText1$LabelAtText2$LabelAtText3", "TextAtButton1$TextAtButton2$TextAtButton3")

The function, in this way, should "explode" the parameters delimited by the separator "$" and detect the number of controls of each type needed, and show these controls into de alert box at the correct position...

After, we could use something like this:

GetiOSMessageBoxValues("Text", 1)   ---> To obtain the text at the index 1

or something like this:

GetiOSMessageBoxValues("Texts")  ---> To obtain if it is possible, as the return of the function, a matrix of results with all the values from the textboxes inside the input box...

or something like this:

GetiOSMessageBoxValues("buttons") ---> To obtain the index of the pushed button, or "none" if the user has not ended...

Then we could do something like this (for example):


WHILE BUTTON$ = "none"
   SLEEP 500
   BUTTON$ = GetiOSMessageBoxValues("button")
WEND
IF BUTTON$ = "1" ....     ---> The user has pressed the button for "Cancel" the input...
   ....
ENDIF
IF BUTTON$ = "0" ....    ---> The user has pressed the button for "Send" the input...
   MESSAGE$ = GetiOSMessageBoxValues("text")
   ....
   PRINT MESSAGE$, 100, 100
   SHOWSCREEN
ENDIF

   

There could be several ways to do that...    but before, the current code should be completed to work fine...

Also may be that Trucidare or Gernot have a complete code that works, and we were redesigning the "wheel"...  :P

Anyway, thanks for your suggestions and interest, I'm sure that someone may have an easy solution to complete the code correctly and we could complete the functions in the better possible way to obtaining all data and events.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Hark0 on 2011-Feb-20
No acabo de entender porqué hay un bucle...

Me explico, ¿no valdría con hacer la llamada y listos? ¿No se detiene la aplicación en espera del resultado de la llamada a GetiOSMessageBoxValues()?
-----
I can not understand why there is a loop ...

I mean, would it not be to make the call and ready? Can not stop the application pending the outcome of the call to GetiOSMessageBoxValues ()?
-----

Ejemplo:

while mainbucle
...
...
render()
...
LOCAL boton=GetiOSMessageBoxValues("mensaje") // Pausa?????? Pause??????

IF boton=0 THEN PRINT "Botón OK",x,y
IF boton=1 THEN PRINT "Botón Cancelar",x,y
...
...
wend


Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Moebius on 2011-Feb-21
QuoteCan not stop the application pending the outcome of the call to GetiOSMessageBoxValues ()
DaCar can do that, I think he just wants to get the text returned completely well first.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: DaCarSoft on 2011-Feb-21
Hola!  =D

Con el código del primer post tal cual, cuando se llama a GetiOSMessageBoxValues, éste devuelve el valor de la variable "resString" hasta ese justo instante, pero la llamada al "alertbox" es un proceso independiente al código de GLBasic, por lo que de alguna forma hay que esperar hasta que el valor de la variable sea el adecuado. Quizá se podría insertar un bucle en el código de GetiOSMessageBoxValues en XCode, para provocar el mismo efecto de espera desde fuera del código GLBasic, pero puede ser util que sean "asíncronos" en algunas condiciones (por ejemplo, para mover el fondo de la pantalla por detras de la ventana en tu juego, mientras se sigue a la espera de la introducción total de datos por parte del usuario), algo así como unas estrellas moviéndose mientras suena la música, ya sabes.   :P

Translation:

Hello!  =D
In the code of the first post as is, when GetiOSMessageBoxValues is called, it returns the value of the "resString" variable in that precise instant. But the call to the "alertbox" is an independent thread to the GLBasic code, because of that you need to wait in any way until the value obtained is the needed. Perhaps it is possible to insert a loop in the code of GetiOSMessageBoxValues under XCode, to create the same wait effect out of the GLBasic code, but it can be handy that asynchrony under certain conditions (for example, to move the background of your game behind the alert, while it continues waiting the user to complete the total input of data). Something like stars moving while the music is playing, you know.   :P
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Feb-21
set a var after calling show - get value of this var in glb and wait until the var is 0 - then glbasic would run normaly after set the var to 0 if a button was clicked

int __iStat = 0;

in the messagebox function set the var to 1 and set to 0 in the event callback.

in glbasic
while the var is 1
    showscreen
wend
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: DaCarSoft on 2011-Feb-22
Thanks Trucidare, I was thinking in using the ".tag" property also making some changes in the code.

I'm focused in solve some troubles with the code, it's to say:

-Under the iPad does not work (iOS 4.2.1 and GLBasic 9.006) it appears to be a problem with "addSubView" but under iPhone, iPod or iPhone 4 the code shows correctly the Alert and gives me the text value.

-I don't know how to work with non english characters.

-I don't know how to avoid the fail when you call to the Alert for a second time... (The second alert freezes when you press a first letter).


This is the code in working, yet unfinished:

for the .mm file:
Code (glbasic) Select

#if defined (TARGET_OS_IPHONE)
#import <UIKit/UIAlert.h>


@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
UITextField* txtValue;
NSString* resButton;
}
- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabels:(NSString*)pLabels andButtons:(NSString*)pButtons;
- (const char*)getValue;
@end

@implementation GLBasicMessageBoxer

- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabels:(NSString*)pLabels andButtons:(NSString*)pButtons
{

UIAlertView* alert = [[UIAlertView alloc] init];
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;

NSArray* aButtons = [pButtons componentsSeparatedByString:@"$"];
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}

if (pLabels != @"") {
double iPos = 70.0;
NSArray* aLabels = [pLabels componentsSeparatedByString:@"$"];
for (NSString* iObject in aLabels){
txtValue = [[UITextField alloc] init];
txtValue.frame = CGRectMake(12.0, iPos, 260.0, 25.0);
txtValue.placeholder = iObject;
txtValue.backgroundColor = [UIColor whiteColor];
txtValue.clearButtonMode = UITextFieldViewModeWhileEditing;
txtValue.keyboardType = UIKeyboardTypeAlphabet;
txtValue.keyboardAppearance = UIKeyboardAppearanceAlert;
txtValue.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtValue.autocorrectionType = UITextAutocorrectionTypeNo;
txtValue.borderStyle = UITextBorderStyleLine;

if (iPos == 70.0) {
[txtValue becomeFirstResponder];
}
iPos = iPos + 30.0;

[alert addSubview:txtValue];


}

}

[alert show];
[alert release];
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resButton = [NSString stringWithFormat:@"%d", buttonIndex];
}

- (const char*)getValue
{
if (resButton != NULL){
return [txtValue.text UTF8String];
}
else
{
return "";
}
}

@end

GLBasicMessageBoxer* newAlert;

extern "C" void iOSMessageBox(const char* pTitle, const char* pMessage, const char* pLabels, const char* pButtons)
{
newAlert = [[GLBasicMessageBoxer alloc]init];
[newAlert showAlert:[NSString stringWithUTF8String:pTitle] andMessage:[NSString stringWithUTF8String:pMessage] andLabels:[NSString stringWithUTF8String:pLabels] andButtons:[NSString stringWithUTF8String:pButtons]];
}

extern "C" const char* GetiOSMessageBoxValues()
{
return [newAlert getValue];
}

#endif


And this, the code for GLBasic:
Code (glbasic) Select

GLOBAL MESSAGE$

IMPORT "C" void iOSMessageBox(const char*,const char*, const char*, const char*)

IMPORT "C" const char* GetiOSMessageBoxValues()


iOSMessageBox("TITLE","Message..." + CHR$(0xD) + CHR$(0xD), "This is a test$and this...", "OK$CANCEL")

WHILE MESSAGE$ = ""
SLEEP 500

MESSAGE$ = GetiOSMessageBoxValues()
WEND

PRINT MENSAJE$, 100, 100
SHOWSCREEN

MESSAGE$ = ""

iOSMessageBox("TITLE2","Message2..." + CHR$(0xD) + CHR$(0xD), "This is a 2nd test$and this...", "OK2$CANCEL2")

WHILE MESSAGE$ = ""
SLEEP 500

MESSAGE$ = GetiOSMessageBoxValues()
WEND

PRINT MESSAGE$, 200, 200
SHOWSCREEN




Can someone help a little?????

Regards.


Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Millerszone on 2011-Feb-28
I have the above code working on the iphone, I'm only using in message.

I have a couple of questions:
If i press OK or Cancel with the text field blank, the screen is blank.

Is it possible to show a background image while the keyboard and messagebox are displayed?

Can the keyboard and messagebox work in landscape mode?

thanks



Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Feb-28
in the while where to wait until ok was pressed only make a set bmp or something similar don't forget to make show screen.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Feb-28
First DaCarSoft - Nice try! some little changes - Untested - please test someone!


Code (glbasic) Select
#if defined (TARGET_OS_IPHONE)
#import <UIKit/UIAlert.h>


@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
UITextField* txtValue;
NSString* resButton;
int response;
}
- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabels:(NSString*)pLabels andButtons:(NSString*)pButtons;
- (const char*)getValue;
@end

@implementation GLBasicMessageBoxer

- (void)showAlert:(NSString*)pTitle andMessage:(NSString*)pMessage andLabels:(NSString*)pLabels andButtons:(NSString*)pButtons
{

UIAlertView* alert = [[UIAlertView alloc] init];
response = 1;
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;

NSArray* aButtons = [pButtons componentsSeparatedByString:@"$"];
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}

if (pLabels != @"") {
double iPos = 70.0;
NSArray* aLabels = [pLabels componentsSeparatedByString:@"$"];
for (NSString* iObject in aLabels){
txtValue = [[UITextField alloc] init];
txtValue.frame = CGRectMake(12.0, iPos, 260.0, 25.0);
txtValue.placeholder = iObject;
txtValue.backgroundColor = [UIColor whiteColor];
txtValue.clearButtonMode = UITextFieldViewModeWhileEditing;
txtValue.keyboardType = UIKeyboardTypeAlphabet;
txtValue.keyboardAppearance = UIKeyboardAppearanceAlert;
txtValue.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtValue.autocorrectionType = UITextAutocorrectionTypeNo;
txtValue.borderStyle = UITextBorderStyleLine;

if (iPos == 70.0) {
[txtValue becomeFirstResponder];
}
iPos = iPos + 30.0;

[alert addSubview:txtValue];


}

}

[alert show];
[alert release];
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resButton = [NSString stringWithFormat:@"%d", buttonIndex];
response = 0;
}

- (const char*)getValue
{
if (resButton != NULL){
return [txtValue.text UTF8String];
}
else
{
return "";
}
}

- (int)getResponse {
return response;
}

@end

GLBasicMessageBoxer* newAlert;

extern "C" void iOSMessageBox(const char* pTitle, const char* pMessage, const char* pLabels, const char* pButtons)
{
newAlert = [[GLBasicMessageBoxer alloc]init];
[newAlert showAlert:[NSString stringWithUTF8String:pTitle] andMessage:[NSString stringWithUTF8String:pMessage] andLabels:[NSString stringWithUTF8String:pLabels] andButtons:[NSString stringWithUTF8String:pButtons]];
}

extern "C" const char* GetiOSMessageBoxValues()
{
return [newAlert getValue];
}

extern "C" int GetiOSMessageState() {
return [newAlert getResponse];
}

#endif


and the GLB Sample:

Code (glbasic) Select

AUTOPAUSE FALSE
SYSTEMPOINTER TRUE

IMPORT "C" void iOSMessageBox(const char*,const char*, const char*, const char*)
IMPORT "C" const char* GetiOSMessageBoxValues()
IMPORT "C" int GetiOSMessageState()

WHILE TRUE
      MOUSESTATE mx,my,b1,b2
      IF b1 THEN DoInput()
      SHOWSCREEN
WEND

FUNCTION DoInput:
       iOSMessageBox("Hallo","Welt","Need some","Input")
       WHILE GetiOSMessageState()
               SETBMP "Abackground.bmp"
               SHOWSCREEN
       WEND
       IF ret$ = GetiOSMessageBoxValues()
              PRINT ret$,0,0
       ENDIF
ENDFUNCTION

Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Millerszone on 2011-Feb-28
trucidare I tested your code, few problems.

When I compile in Xcode I get this error on all the "self.response"
Here is the error: "Object cannot be set - either readonly property or no setter found"

So I removed all the "self." I get no errors in xcode, but I see no text on the screen after I hit submit,
then if I touch the screen again, the keyboard pops back up, the first letter I type, the program locks up.
This is probably do to me removing the "self."

Also when I first load the app the screen is blank until I touch the screen.

Thanks for working on the iphone keyboard, it's a lot better than messing with a custom keyboard.

This is what it looks like so far:
(http://www.americantc.com/Images/iphoneKeyboard.png)
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Feb-28
uhm ok so i have to test it myself to avoid these problems. thanks for testing.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Mar-02
ok i´m working on this - but there are some problems with compiling :/ i think its because iphone is jailbroken.
sorry for waiting :/

EDIT:// OK found something - i forgot to run this code in main thread. sorry update is comming.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Millerszone on 2011-Mar-02
Quote from: trucidare on 2011-Mar-02
ok i´m working on this - but there are some problems with compiling :/ i think its because iphone is jailbroken.
sorry for waiting :/

EDIT:// OK found something - i forgot to run this code in main thread. sorry update is comming.

Cool, i'll be here to test.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: DaCarSoft on 2011-Mar-02
Hi!

First of all, I would like to say that I appreciate the interest in the testing of this code, I think that it is possible to complete the code, and expand it (for example to rotate the view depending on the device orientation)  with the collaboration of all people   :)

I know that the code could be better, but I'm focused in solve a problem related to the addition of the textfields to the UIAlert, and I suppose that it may be the origin of some of the problems found related to the testing of the code... if you test the code in an iDevice with iOS 4.0.1 all runs fine, but if you test the code under 4.2.1, the app crashes when the "addSubview" is called...  :S

If I comment the next line the code works for me (without textboxes): 

[alert addSubview:txtValue];

obviously changing it with this:

// [alert addSubview:txtValue];


But my question is...   Why the same code runs in older iOS but don't work in the last 4.2.1 version????
Can someone confirm this???

At the other side, it is needed to "release" or destroy the objects created because (for me) the code does not work if I call to the functions a second time...   I think that I know how can I do that...    I will continue with my testing and I'll paste here the changes.

Also, may be I'm totally wrong because I don't know so much about XCode, these are the first lines of code that I try in it  :P


Good luck!!!
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Millerszone on 2011-Mar-03
I also appreciate you guys getting the IOS keyboard working. I wish I could help more, but I'm still learning C/Objective C.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Mar-03
it works because they changed something in 4.2.1 - glbasic runs in a own thread and with 4.2.1 uikit must run in the main thread so i have to put some lines into this wrapper to run this in mainthread.
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: DaCarSoft on 2011-Mar-04
Then...  I suppose that it is needed to send to "PerformSelectorOnMainThread" the four arguments of "showAlert".

Perhaps this code may help:

http://goodliffe.blogspot.com/2011/01/ios-performselectoronmainthread-with.html

Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Mar-06
Yep thanks - i did the perform trick in openfeint wrapper a few months ago.

sorry guys it tooks a bit longer but here is the fully working code and a sample.
Why two \n in Description? - Because the Button wouldnt show nicely. hehe


Code (glbasic) Select
#import <UIKit/UIAlert.h>

const char* __pResult;


@interface GLBasicMessageBoxer: NSObject <UIAlertViewDelegate>
{
UITextField* txtValue;
NSString* resButton;
int response;
NSString *pTitle,*pMessage,*pLabels,*pButtons,*pResult;

}
- (void)showBox:(NSString*)_pTitle andMessage:(NSString*)_pMessage andLabels:(NSString*)_pLabels andButtons:(NSString*)_pButtons;
- (void)showAlert;
- (void)setValue;
@end

@implementation GLBasicMessageBoxer

- (void)showAlert
{


UIAlertView* alert = [[UIAlertView alloc] init];
response = 1;
alert.title = pTitle;
alert.message = pMessage;
alert.delegate = self;

NSArray* aButtons = [pButtons componentsSeparatedByString:@"$"];
for (NSString* iObject in aButtons){
[alert addButtonWithTitle:iObject];
}

if (pLabels != @"") {
double iPos = 70.0;
NSArray* aLabels = [pLabels componentsSeparatedByString:@"$"];
for (NSString* iObject in aLabels){
txtValue = [[UITextField alloc] init];
txtValue.frame = CGRectMake(12.0, iPos, 260.0, 25.0);
txtValue.placeholder = iObject;
txtValue.backgroundColor = [UIColor whiteColor];
txtValue.clearButtonMode = UITextFieldViewModeWhileEditing;
txtValue.keyboardType = UIKeyboardTypeAlphabet;
txtValue.keyboardAppearance = UIKeyboardAppearanceAlert;
txtValue.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtValue.autocorrectionType = UITextAutocorrectionTypeNo;
txtValue.borderStyle = UITextBorderStyleLine;

if (iPos == 70.0) {
[txtValue becomeFirstResponder];
}
iPos = iPos + 30.0;

[alert addSubview:txtValue];


}

}

[alert show];
[alert release];
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
resButton = [NSString stringWithFormat:@"%d", buttonIndex];
response = 0;
}

- (void)setValue
{
if (resButton != NULL){
__pResult = [txtValue.text UTF8String];
}
else
{
__pResult = "NO_DATA";
}
}

- (int)getResponse {
return response;
}

- (void) showBox:(NSString*)_pTitle andMessage:(NSString*)_pMessage andLabels:(NSString*)_pLabels andButtons:(NSString*)_pButtons {
pResult = [[NSString alloc]init];
pTitle = [[NSString alloc]init];
pMessage = [[NSString alloc]init];
pButtons = [[NSString alloc]init];
pLabels = [[NSString alloc]init];

pTitle = _pTitle;
pMessage = _pMessage;
pLabels = _pLabels;
pButtons = _pButtons;
[self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO];
}

- (void)_getValue {
[self performSelectorOnMainThread:@selector(setValue) withObject:nil waitUntilDone:YES];
}

@end

GLBasicMessageBoxer* newAlert;

extern "C" void iOSMessageBox(const char* pTitle, const char* pMessage, const char* pLabels, const char* pButtons)
{
newAlert = [[GLBasicMessageBoxer alloc]init];
[newAlert showBox:[NSString stringWithUTF8String:pTitle] andMessage:[NSString stringWithUTF8String:pMessage] andLabels:[NSString stringWithUTF8String:pLabels] andButtons:[NSString stringWithUTF8String:pButtons]];
}

extern "C" const char* GetiOSMessageBoxValues()
{
[newAlert _getValue];
return __pResult;
}

extern "C" int GetiOSMessageState() {
return [newAlert getResponse];
}


the sample i used

Code (glbasic) Select
// Project iPhoneKeyboard
// Created 06.03.2011 21:48 Uhr
// by codemini

AUTOPAUSE FALSE
SYSTEMPOINTER TRUE

IMPORT "C" void iOSMessageBox(const char*,const char*, const char*, const char*)
IMPORT "C" const char* GetiOSMessageBoxValues()
IMPORT "C" int GetiOSMessageState()

LOCAL mx,my,b1,b2

WHILE TRUE
      MOUSESTATE mx,my,b1,b2
      IF b1 THEN DoInput()
      SHOWSCREEN
WEND

FUNCTION DoInput:
LOCAL ret$ = ""
       iOSMessageBox("Highscore","Please Enter your Name\n\n","Name","Submit")
       WHILE GetiOSMessageState()
               //Here some background image action
               SHOWSCREEN
       WEND
       ret$ = GetiOSMessageBoxValues()
       IF ret$ <> ""
PRINT ret$,0,0
stdout ret$
ELSE
PRINT "No_Data",0,0
stdout "NoData"
       ENDIF
ENDFUNCTION




GDB Output:
Code (glbasic) Select
backing: 320 x 480
Init GFX
AudioStreamBasicDescription:  2 ch,  44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
Init Finalized
Nils Tonagel





[attachment deleted by admin]
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Marmor on 2011-Mar-06
finally a ios keyboard  !!  thx truci you are a "hero"  :good:
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Millerszone on 2011-Mar-07
I finished my custom keyboard for the iPhone yesterday, but this will be much better.

Thanks  trucidare.  :good:
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: Marmor on 2011-Mar-07
hmm with the original code i cant see or press the submit button

this is what i get if i call the iosmessagbox with ptitle ="",pmessage =""


(http://www.blitzforum.de/upload/file.php?id=10382)

Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: trucidare on 2011-Mar-07
uhm i think its my bad screen setting in mac ide. let me hav a look

EDIT:// cant reproduce that... if i leave title and message empty it looks like

EDIT:// ok seems that you are on ios < 4 so you have to move the window manually - try to set
Code (glbasic) Select
alert.transform = CGAffineTransformTranslate( alert.transform, 0.0, -20.0 );


somewhere before show ... hmm or after show??? have a try!

and here a simpler Basic Version:

Code (glbasic) Select
FUNCTION iINPUT$: title$, message$, label$, button$
local result$
grabsprite 1000,0,0,320,480
iOSMessageBox(title$,message$,label$,button$)
while GetiOSMessageState()
drawsprite 1,0,0
showscreen
wend
result$ = GetiOSMessageBoxValues()
loadsprite "",1000
return result$
endfunction



[attachment deleted by admin]
Title: Re: Keyboard "InputBox" for iOS (Help needed, near to completion!)
Post by: adaz on 2014-Jul-09
The text field does not appear on iOS 7, and the keyboard doesn't come up. I don't know what to change in the code:(