如何从特定索引处的数组中删除对象

时间:2022-10-03 20:10:30

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.

我正在解析xml文件并从xml文件中获取数据并将其存储在数组中,并进一步存储到UITableView行。我想在第5个索引'\ U2019'中删除多余的单词,并希望将单词'i'和'm alone alone'合并到一行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 个解决方案

#1


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.

编辑:你可以调用[tableView reloadData];为了删除该行,假设您在操作数组之前已经加载了tableView。

You can merge 2 strings together via:

您可以通过以下方式合并2个字符串

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!

希望有所帮助!

#2


0  

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

您可以使用NSMutable数组及其名为removeObjectAtIndex的方法:

#1


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.

编辑:你可以调用[tableView reloadData];为了删除该行,假设您在操作数组之前已经加载了tableView。

You can merge 2 strings together via:

您可以通过以下方式合并2个字符串

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!

希望有所帮助!

#2


0  

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

您可以使用NSMutable数组及其名为removeObjectAtIndex的方法: