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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-10-2009, 12:26 PM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 28
Csprocket777 is on a distinguished road
Default Toolbar in actionsheet, dismiss actionsheet with button in toolbar. Possible?

Ok. I want a pickerview appearing overtop a table when a user edits a text field in the table. I'm using an actionsheet to do this. It's working perfectly so far.

But I have no way to dismiss the actionsheet once it appears. It was surprisingly easy to put a toolbar at the top of the actionsheet and a "Done" button on that. How do I use the done button to dismiss the actionsheet and pass the values back to the field that brought it up?
Csprocket777 is offline   Reply With Quote
Old 04-10-2009, 01:38 PM   #2 (permalink)
Confused
 
Join Date: Mar 2009
Location: New York
Age: 37
Posts: 88
nycdude777 is on a distinguished road
Default

Quote:
Originally Posted by Csprocket777 View Post
Ok. I want a pickerview appearing overtop a table when a user edits a text field in the table. I'm using an actionsheet to do this. It's working perfectly so far.

But I have no way to dismiss the actionsheet once it appears. It was surprisingly easy to put a toolbar at the top of the actionsheet and a "Done" button on that. How do I use the done button to dismiss the actionsheet and pass the values back to the field that brought it up?
Have you tried something like this:

When you add a button to the toolbar, add a target with selector to run a custom method. When the user clicks the button, that method will execute. inside that method, call the dismissWithClickedButtonIndex:animated: method of the UIActionSheet

Now the actionsheet must have the delegate set to self, so when you call it, it should dismiss the sctionsheet and fire the event, so you need to nadle the dismissWithClickedButtonIndex event too if you want to do anything else once the suer clicks the button. I think it should dismiss the action sheet automatically, if I am thinking correctly, and I'd like to think that I am, in which case it would mean that I am finally getting a hang of this...
nycdude777 is offline   Reply With Quote
Old 04-10-2009, 01:50 PM   #3 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 28
Csprocket777 is on a distinguished road
Default

good lord that worked perfectly! Thanks a ton!
Csprocket777 is offline   Reply With Quote
Old 04-10-2009, 02:06 PM   #4 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 28
Csprocket777 is on a distinguished road
Default

Incase anyone is looking for how I did this (I've seen many posts asking about this), here's the code.

First off, I'm doing this in a TableViewController:

In my H file:
Code:
@interface AddItemView : UITableViewController <UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UIActionSheetDelegate>{
	UIPickerView *pickerView;
	UIToolbar *pickerToolbar;
	UIActionSheet *pickerViewPopup;
}

- (void) showPicker;
In my M file:

This triggers the actionsheet to appear when the user enters the specified UITextField:
Code:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
	if(textField == newItem.quantityF)
	{
		[textField resignFirstResponder];
		[self showPicker];
		[pickerView selectRow:1 inComponent:3 animated:YES];
	}
}
This shows and hides the actionsheet containing the pickerView:
Code:
- (void) showPicker {
	pickerViewPopup = [[UIActionSheet alloc] initWithTitle:@"How many?"
													  delegate:self
											 cancelButtonTitle:nil
										destructiveButtonTitle:nil
											 otherButtonTitles:nil];
	
	// Add the picker
	pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,44,0,0)];
	
	pickerView.delegate = self;
	pickerView.showsSelectionIndicator = YES;    // note this is default to NO
	
	pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
	pickerToolbar.barStyle = UIBarStyleBlackOpaque;
	[pickerToolbar sizeToFit];
	
	NSMutableArray *barItems = [[NSMutableArray alloc] init];
	
	UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
	[barItems addObject:flexSpace];
	
	UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closePicker:)];
	[barItems addObject:doneBtn];

	[pickerToolbar setItems:barItems animated:YES];
	
	[pickerViewPopup addSubview:pickerToolbar];
	[pickerViewPopup addSubview:pickerView];
	[pickerViewPopup showInView:self.view];
	[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];
	
}


- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
}

-(BOOL)closePicker:(id)sender
{
	[pickerViewPopup dismissWithClickedButtonIndex:0 animated:YES];
	[pickerView release];
	[pickerToolbar release];
	[pickerViewPopup release];
	return YES;
}
Here's the pickerView setup: (In the M file)
Code:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
	NSArray *rowTitles = [NSArray arrayWithObjects:@"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil];
	return [rowTitles objectAtIndex:row];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
	return 4;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
	return 10;
}


-(void)pickerView:(UIPickerView *)aPickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{	
}
Csprocket777 is offline   Reply With Quote
Old 01-14-2010, 08:35 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 12
malik_vijay158 is on a distinguished road
Default

hi.....

i am creating a table cell using interface builder.....having 2 text field......

at the end of the row i am creating a Accessory button.......when i tap on accessory button.....Action sheet will open........showing NUMERIC,NON NUMERIC,CANCEL button..........

i want suppose i click on Numeric button i will display.....NUMERIC in the text Field.....

thanx a lot.....
malik_vijay158 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 329
7 members and 322 guests
blueorb, guusleijsten, jbro, Kryckter, LEARN2MAKE, n00b, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0