ios - 我在 tableview 上显示的代码中的错误在哪里?

标签 ios objective-c uitableview

我尝试从 web 服务加载一个数组并显示在 TableView 上。这是我的 TableView 。但是有一个错误。分支名称是

穆罕默德·福代洛兹坎,

SELAHATTİN KOÇAK,

Mehmet Süner Eken 汽油

Hasan Katkıcı 汽油

等等

等等

但是表格 View 是这样显示的

我该如何解决这个问题?

enter image description here

数组代码:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict
{
  if ( [elementName isEqualToString:@"Branchname"] )
  {
    teveRetorno = YES;
  }
  else if ( [elementName isEqualToString:@"GetBranchNameResult"] )
  {
    myArray = [[NSMutableArray alloc] init];
  }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
  if (teveRetorno) {
    //[retornoSOAP appendString:string];
    [myArray addObject:string];
  }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
  if ( [elementName isEqualToString:@"Branchname"] ) {
    NSLog(@"My Array %@",myArray);

    [[self tableView]reloadData];

    //retornoSOAP = nil;
    teveRetorno = NO;
  }
}

表格代码

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  #warning Incomplete method implementation.
  // Return the number of rows in the section.

  return [self.myArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  }

  cell.textLabel.text =[myArray objectAtIndex:indexPath.row];
  return cell;
}

最佳答案

您的表格 View 或输出没有任何问题。您的 XMLParser 被某些字符 (Ö) 弄糊涂了,并且过早地调用了 didStartElement。看看这个 - NSXMLParser divides strings containing foreign(unicode) characters

关于ios - 我在 tableview 上显示的代码中的错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17092117/

相关文章:

ios - 无需滚动 Swift 即可动态更新单元格高度

iphone - 从 fetchedresultsController 中删除错误,索引处没有部分

ios - 快速链接所有搜索栏结果到同一个 View Controller

ios - 动画(旋转)UIBarButtonItem 自定义按钮

iphone - 防止应用程序缓存在 iOS 上提取文件

ios - UIActivityIndi​​catorView 无法正常工作

ios - 如何在 Xamarin 中实现文档提供程序扩展?

iphone - CGAffineTransformMakeRotation错误

ios - CGAffineTransformMakeScale 动画不工作

ios - 如何使用 UITableView