开发者

Updating label based on picker value the very first time a view is loaded

I'm new to iPhone development, so my apologies if this is a ridiculous question.

I'm following a sample from a book where it creates a exchange rate UIPicker and when you select one of the entries, it displays the conversion of US dollars into whatever currency is picked.

I want the value to be updated in my label before I start changing the value from the picker.

The very first time i enter my US dollar value in the textbox and I click on the "Return" button, i want the label to update and displays its equivalent value in whatever currency is currently selected in the picker.

I have the correct code in the didSelectRow event, and that part works as long as i start spinning the picker's component wheels, so I thought I'd take that code and put it in a function which would have one parameter i.e. row and this function would then be called from didSelectRow where the row parameter would be passed and then I would:

This is the code from the didSelectRow开发者_StackOverflow:

float rate = [[exchangeRates objectAtIndex:row] floatValue];
float dollars = [dollarText.text floatValue];
float result = dollars * rate;

NSString *resultString = [[NSString alloc] initWithFormat:@"%.2f USD = %.2f %@", dollars, result, [countryNames objectAtIndex:row]];

resultLabel.text = resultString;
[resultString release];

Call this function when the "Did End on Exit" event for the textbox but my I'm having two problems:

  1. What is the correct way to write the function. Whatever way I write the function, I get various errors/warnings

  2. How do i get the currently select row of the picker, so that I can pass it to this function when the "Did End on Exit" event occurs when i click on the "Return" button.

Thanks

T.


I am not sure, I completely understood you what exactly you are trying to do here. but still I am going ahead what you can do here is:

first of all declare an class variable of type int which will store the row index whenever didSelectRow delegate method will be called, mean time create a method like:

-(void)updateLabel:(int) rowIndex

{

float rate = [[exchangeRates objectAtIndex:row] floatValue];
float dollars = [dollarText.text floatValue];
float result = dollars * rate;

NSString *resultString = [[NSString alloc] initWithFormat:@"%.2f USD = %.2f %@",       dollars, result, [countryNames objectAtIndex:rowIndex]]; // here it will go rowIndex which is the row value you stored in your variable



resultLabel.text = resultString;
   [resultString release];

}

and call this method when you hit return. I hope this helps you.

~Manoj

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜