views:

346

answers:

3

hi, i am making an application of iphone, in which i have a table view, on every row of table view i have created a button programmatically & on its click method am showing picker view. Picker view showing perfectly, on picker view's toolbar i have 2 barbuttonitem named Done & Cancel. i have added below code in Picker view's delegate method

but button title is not changing with this delegate method

static int _selectedRow;

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
     NSString *title = [pickarray objectAtIndex:_selectedRow];
     //[pickarray removeObjectAtIndex:_selectedRow];
     [pickarray insertObject:title atIndex:_selectedRow];
     [table reloadData];
}

Any ideas how to show selected row title on button?

A: 

I don't see where you assign the value of _selectedRow, or where you use the parameter "row" in didSelectRow. I don't think your engine is connected to your wheels.

Amagrammer
i have added below code -(IBAction)btnpickclick:(id)sender { UIButton btn = (UIButton*)sender;_selectedRow = btn.tag; tool.hidden = FALSE; pick.hidden = FALSE; } i am bit confused in didselectrow delegate of pickerview what should i write to get the title on button on selection pieckerview row.
A: 

Fetch the selected row data and assign it to your button text. Below is what I did in my code. See if this helps


[breedButton setTitle:[pickerData objectAtIndex:[pickerView selectedRowInComponent:0]] forState:UIControlStateNormal];

Do this in your picker delegate method


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

breedButton is my button. pickerData is my array of strings I am showing in the picker. pickerView is my picker view object.

AJ
actually i have solved my issue regarding button's title. your solution is for for 1 button title but i have created 1 button in cellforrowatindexpath in tableview delegate, now the issue is i have to show button title is "select" cancel of pickerview. Any ideas?
A: 

i have solved my issues by own. thanx for the suggestions