0

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

穆罕默德·福代洛兹坎,

SELAHATTİN KOÇAK,

Mehmet Süner Eken 汽油

Hasan Katkıcı 汽油

ETC

ETC

但是表格视图向我展示了那样

我如何解决这个问题?

在此处输入图像描述

数组代码:

-(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;
}
4

2 回答 2

2

您的表格视图或输出没有任何问题。您的 XMLParser 被某些字符 (Ö) 弄糊涂了,并且过早地调用了 didStartElement。看看这个 - NSXMLParser 分割包含外来(unicode)字符的字符串

于 2013-06-13T17:44:43.203 回答
0

如果您询问文本被截断的原因,请为单元格的 textLabel 设置adjustsFontSizeToFitWidth。如果该问题修复它,则手动降低 textLabel 的字体。

于 2013-06-13T17:38:33.100 回答