开发者

How to add the static data into the Dynamic array in iPhone?

开发者 https://www.devze.com 2023-02-10 07:20 出处:网络
I want to add the static contents into the Mutable Array. I have parsed the data using XML parsing and stored the dynamic data into the mutable array. Now i want to add the static string into that Mut

I want to add the static contents into the Mutable Array. I have parsed the data using XML parsing and stored the dynamic data into the mutable array. Now i want to add the static string into that Mutable Array. So how can i add that?

For Eg:

In my dynamic Array of content is,

  {
       first,
       third, 
       fourth,
       fifth.
  }

I want to add the static String into the 1st index of array. Because my requirement is, displayed the static content into the 1st position.

开发者_JAVA技巧

Expected output:

  {
       first,
       second,   //Add the static data into the First index of Array 
       third, 
       fourth,
       fifth.
  }

So how can i do this?

Thanks.


If I understand what you mean. You can use:

[NSMutableArray insertObject:atIndex:]

Supposing myArray is the instance of NSMutableArray:

[myArray insertObject:@"second" atIndex:1];

instead of NSString you can insert every object you want.


After creating NSMutableArray from XML parsing you can implement like this,

suppoose In XMLArray you having your xml data now you want to insert static date at any location,

NSMutableArray *tempArray=[NSMutable array];
for(int i=0;i<[XMLArray count];i++)
{
  if(i==1)//accrding to you
      [tempArray addObject:yourStaticData];//yourStaticData is object having your data.
  else
    [tempArray addObject:[XMLArray objectAtIndex:i]];
}

//use tempArray according to you.
0

精彩评论

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