我尝试从 web 服务加载一个数组并显示在 TableView 上。这是我的 TableView 。但是有一个错误。分支名称是
穆罕默德·福代洛兹坎,
SELAHATTİN KOÇAK,
Mehmet Süner Eken 汽油
Hasan Katkıcı 汽油
等等
等等
但是表格 View 是这样显示的
我该如何解决这个问题?
数组代码:
-(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/