Shikha
Shikha

Reputation: 7

Assign an array of a single string and then fetch its value after modifying it

I have declared an array in viewDidLoad.

 -(void) viewDidLoad{
   status=[[NSMutableArray alloc] init];
   [status addObject:@"Pending"];
 }

Now in some function I need to change the value of "Pending" to "Approved". and then check that condition in cellforRow. What I am currently doing is :

some function: [[ objectAtIndex:0] addObject: "Approved"];

cellForRow:  

if( [[status objectAtIndex:0] isEqual:@"Pending"){
  //do this
}
else if ([[status objectAtIndex:0] isEqual:@"Approved"){
  //do that
}

It is throwing an exception:

NSInvalidArgumentException :[__ NSCFCConstantString addObject:]: unrecognized selector sent to instance 

Upvotes: 0

Views: 50

Answers (2)

Paras Joshi
Paras Joshi

Reputation: 20541

Just Replace value with index number of an Array

[yourArray replaceObjectAtIndex:0 withObject:@"Approved"];

:)

Upvotes: 0

KAREEM MAHAMMED
KAREEM MAHAMMED

Reputation: 1695

You need to add code is like that in your some function

[status replaceObjectAtIndex:0 withObject:"Approved"];

Upvotes: 1

Related Questions