как удалить объект из массива по определенному индексу - PullRequest
2 голосов
/ 15 августа 2011

Я делаю разбор файла xml, извлекаю данные из файла xml и сохраняю их в массиве и далее в строках UITableView.Я хочу удалить лишнее слово в 5-м индексе '\ U2019' и хочу объединить слова 'i' и 'm all one' в одну строку для 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"

связка кода:

- (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 голос
/ 15 августа 2011

Легко удалить объект по определенному индексу.Попробуйте:

[blogtitle removeObjectAtIndex:index];

РЕДАКТИРОВАТЬ: Вы можете вызвать [tableView reloadData];, чтобы удалить строку, предполагая, что вы уже загрузили tableView, ДО того, как вы манипулировали массивом.

Вы можете объединить 2 строки вместе с помощью:

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

и заменить один объект в массиве другим с помощью:

[blogtitle replaceObjectAtIndex:index withObject:mergedString];

Надеюсь, это поможет!

0 голосов
/ 15 августа 2011

Вы можете использовать массив NSMutable и его метод с именем removeObjectAtIndex:

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...