2

I am doing parsing on xml file and fetched data from xml file and store that in array and further to rows of UITableView. I want to remove the extra word at 5th index '\U2019' and want to merge word 'i' and 'm all alone' to one row f UITableView.

"WHERE DOES LOVE LIVE",
"TRANSFORMATION OF THE SELF",
"EMPATHY STRUCTURES",
"MORE QUESTIONS THAN ANSWERS",
I,
"\U2019",
"M ALL ALONE",
"THE WILL TO LIVE",
"THE GUILT OF SELF DENIAL",
HOPELESSNESS,
"SOCIAL WANNABIES",
"THE POWER OF HOPE"

bunch of code:

- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:
  (NSIndexPath *)indexPath
 {   static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
}

if(indexPath.row > 0) 
{ cell.textLabel.text = [blogtitle objectAtIndex: indexPath.row];
}}`
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string
 {
 NSString *newString = [string  stringByTrimmingCharactersInSet:
 [NSCharacterSet  whitespaceAndNewlineCharacterSet]];

// save the characters for the current item...
if ( [currentElement isEqualToString:@"title"]) 
{ 
    if ([newString length] > 0) 
    {
      // NSMutableString *base64String = [newString base64EncodedString]; 

      [blogtitle addObject:newString];
      }         

    NSLog(@"blogtiltlearray...%@",blogtitle);
 }}`

2 Answers 2

1

It's easy to remove an object at a specific index. Try:

[blogtitle removeObjectAtIndex:index];

EDIT: You can call [tableView reloadData]; in order to remove the row, assuming you've already loaded the tableView BEFORE you manipulated the array.

You can merge 2 strings together via:

NSString * mergedString = [NSString stringWithFormat:@"%@%@", string1, string2];

and you can replace one object in an array with another via:

[blogtitle replaceObjectAtIndex:index withObject:mergedString];

Hope that helps!

Sign up to request clarification or add additional context in comments.

4 Comments

i have tried this but what about the empty space left after removing object at index. i don't want to show that empty space in table view.
After removing, reload the table like [tableName reloadData];
thank you..it works but how can i merge the object at index 6 with object at index 4.
I have added code that will show you how to merge 2 different strings together. Don't forget to accept the answer to that people will know to use it later if they have the same problem!
0

You can use NSMutable array and the method of it named removeObjectAtIndex:

4 Comments

Then there should be no problem NSMutableArray corrects indexes after removing or inserting objects, so there will be no "empty space" as you said on the above comment.
i am removing that at 'cellforrowatindex'- method [blogtitle removeObjectAtIndex:0]; cell.textLabel.text = [blogtitle objectAtIndex: indexPath.row]; and it crashes
You should not remove that in cellForRowAtIndexPath method. You need to remove it in between two method calls named willBeginUpdate and didEndUpdate. Directly removing object mutates the integrity of tablView.
i am agree, before loading into tableview i just removed the object at index at parserDidEndDocument:. But now its not the main problem , problem is in merging

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.