我尝试从 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;
}