Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 10-31-2008, 08:04 AM   #10 (permalink)
Forsworn
Registered Member
 
Forsworn's Avatar
 
Join Date: Oct 2008
Location: Germany
Posts: 504
Forsworn is on a distinguished road
Default

I got it!

You have to add these methods:

Preparation:
Code:
<UITextFieldDelegate> //import the Delegate protocol
- (void) presentSheet; //declare method in header file
Show the alert:
Code:
- (void) presentSheet { 	
	UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"New Alert" message:@"your message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
	[myAlert addTextFieldWithValue:nil label:@"I'm the Placeholder"];
	
	[[myAlert textField] setDelegate:self];
	[[myAlert textField] setTextAlignment:UITextAlignmentCenter];
	[[myAlert textField] becomeFirstResponder];
	[myAlert show];
	[myAlert release];
	myAlert = nil;
}
Get clicked button and string:
Code:
- (void)alertView:(UIAlertView *)alertView 
clickedButtonAtIndex:(NSInteger)buttonIndex 
{ if ([alertView title] == @"New Alert") { //Only for one specific alert
	
	NSString *myString = [[alertView textField]text]; //Get the string
	NSLog(@"User Pressed Button %d and String is: %@", buttonIndex + 1, myString); //Put it on the debugger
	
	if ([[[alertView textField]text]length] <= 0 || buttonIndex ==0) 
		return; //If cancel or 0 length string the string doesn't matter
	
	if (buttonIndex == 1) {
		//Setup an object or do sth. else here
	}
}
}
Done button:
Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	NSLog(@"Dismiss Return");
	[self alertView:(UIAlertView *)[textField  superview] clickedButtonAtIndex:1];
	[(UIAlertView *)[textField  superview] dismissWithClickedButtonIndex:1 animated:NO];
	
	return NO;
}

Last edited by Forsworn; 10-31-2008 at 03:56 PM.
Forsworn is offline   Reply With Quote
 

» Advertisements
» Online Users: 402
17 members and 385 guests
askb, Chickenrig, CMSLdesign, Code.ei, dre, guillermotricia, ilmman, jaychoupham, LEARN2MAKE, n00b, NSString, Paul Slocum, pbart, roof44, Speed, teebee74, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,591
Threads: 94,083
Posts: 402,777
Top Poster: BrianSlick (7,990)
Welcome to our newest member, guillermotricia
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:28 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.