简体   繁体   中英

How to store UITextView data into NSMutablearray?

This time I am having problems with not being able to store some data in an NSMutablearray.

The process is like this:

I click on a button that loads a UIPopOver and I make the selection of a product and its amount, through UIPIckerView, when I click the Done button, the amount, product and total price appears on a UITextView. I'm ok with that.

The problem is that I need to store each selection from the UIPickerView in the NSMutablearray for a later calculation of the sum of all products selected, but it is not storing in the NSMutablerarray.

So, anyone could help???

-(void)donePressed{



//Cálculo do valor a pagar
float quantFlt = [[arrayQtdProdutos objectAtIndex:[categoryPicker selectedRowInComponent:1]] floatValue];
float valorFlt = [[valorArray objectAtIndex:[categoryPicker selectedRowInComponent:0]] floatValue];
float total = quantFlt * valorFlt;

_msg = [NSString stringWithFormat: @"%@ - %@ - R$ %.2f",
        [arrayQtdProdutos objectAtIndex:[categoryPicker selectedRowInComponent:1]],
        [arrayOfCategories objectAtIndex:[categoryPicker selectedRowInComponent:0]],
        total];

_txtViewProdutos.text = [NSString stringWithFormat:@"%@ \n%@", _txtViewProdutos.text, _msg];

[arrayProdutosComprados addObject:_msg];
NSLog(@"%i", arrayProdutosComprados.count);

[popOverController dismissPopoverAnimated:YES];
}

This is the correct code with the help of @SPA.

-(void)donePressed{

//Cálculo do valor a pagar
float quantFlt = [[arrayQtdProdutos objectAtIndex:[categoryPicker selectedRowInComponent:1]] floatValue];
float valorFlt = [[valorArray objectAtIndex:[categoryPicker selectedRowInComponent:0]] floatValue];
float total = quantFlt * valorFlt;

_msg = [NSString stringWithFormat: @"%@ - %@ - R$ %.2f",
    [arrayQtdProdutos objectAtIndex:[categoryPicker selectedRowInComponent:1]],
    [arrayOfCategories objectAtIndex:[categoryPicker selectedRowInComponent:0]],
    total];

_txtViewProdutos.text = [NSString stringWithFormat:@"%@ \n%@", _txtViewProdutos.text, _msg];

[arrayProdutosComprados addObject:_msg];
NSLog(@"%i", arrayProdutosComprados.count);

[popOverController dismissPopoverAnimated:YES];
}


- (void)viewDidLoad
{
[super viewDidLoad];

arrayProdutosComprados = [NSMutableArray new];
}

我同意SPA,arrayProdutosComprados为零的可能性更大。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM