Keyboard "InputBox" for iOS (Help needed, near to completion!)

Previous topic - Next topic

DaCarSoft

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!!!
"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.

Millerszone

I also appreciate you guys getting the IOS keyboard working. I wish I could help more, but I'm still learning C/Objective C.
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

trucidare

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.
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

DaCarSoft

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

"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.

trucidare

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]
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Marmor

finally a ios keyboard  !!  thx truci you are a "hero"  :good:

Millerszone

I finished my custom keyboard for the iPhone yesterday, but this will be much better.

Thanks  trucidare.  :good:
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

Marmor

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 =""





trucidare

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]
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

adaz

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:(