Web サービスから配列を読み込んで tableview に表示しようとしましたが、問題があります。
テーブルビューに重複したフィールドを表示したくありません。
テーブルにフィールドを1つだけ表示したい。
今私が持っています :
1234
1235
1234
6544
2234
6544
たとえば、1234 と 6544 は重複しています
配列コードをロード:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict
{
if ( [elementName isEqualToString:@"BranchID"] )
{
teveRetorno = YES;
}
else if ( [elementName isEqualToString:@"GetBranchResult"] )
{
myArray = [[NSMutableArray alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (teveRetorno)
{
[myArray addObject:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ( [elementName isEqualToString:@"BranchID"] )
{
[[self tableView]reloadData];
}
teveRetorno = NO;
}
テーブル コード:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)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];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}