解析後にすべてのUITableView
値が表示されませんXML
。1 行のみを返します。xml を解析した後、全体ではなく 1 行だけが表示されるのはなぜArrayList
ですか? xml php ページを確認しました。すべての値が正常に表示されています。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[xmlcont xmlbanktransfer] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSUInteger const kMagnitudeImageTag = 0;
static NSUInteger const kLocationLabelTag = 4;
static NSUInteger const klocationtag = 6;
static NSUInteger const kacctag = 8;
static NSUInteger const knameLabelTag = 9;
UIImageView *magnitudeImage = nil;
UILabel*locationLabel = nil;
UILabel*locationtag=nil;
UILabel*acc=nil;
UILabel*nameLabel= nil;
//NSMutableArray *cont = [xmlcont tweets];
// Tweet *current = [cont objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
/*//common settings
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
cell.imageView.clipsToBounds = YES;
*/
}
for(UIView *view in cell.contentView.subviews)
{
if ([view isKindOfClass:[UIView class]])
{
[view removeFromSuperview];
}
}
NSMutableArray *cont = [xmlcont xmlbanktransfer];
trans *current= [cont objectAtIndex:indexPath.row];
NSLog(@"sd %@",current.date);
NSLog(@"sd %@",current.name);
locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(5,10, 250, 20)];
locationLabel.tag = kLocationLabelTag;
locationLabel.font = [UIFont boldSystemFontOfSize:15];
[cell.contentView addSubview:locationLabel];
locationLabel.text=current.name;
locationLabel.textColor=[UIColor colorWithRed:0.050 green:0.278 blue:0.392 alpha:1];
//locationLabel.backgroundColor=[UIColor lightGrayColor];
locationLabel.backgroundColor=[UIColor colorWithRed:225 green:225 blue:225 alpha:0] ;
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(180,10, 250, 20)];
nameLabel.tag = knameLabelTag;
nameLabel.font = [UIFont systemFontOfSize:13];
[cell.contentView addSubview:nameLabel];
nameLabel.text=current.date ;
nameLabel.textColor=[UIColor colorWithRed:0.050 green:0.278 blue:0.392 alpha:1];
//locationLabel.backgroundColor=[UIColor lightGrayColor];
nameLabel.backgroundColor=[UIColor colorWithRed:225 green:225 blue:225 alpha:0] ;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
xml を解析するためのコード:
xmlbanktransfer=[[NSMutableArray alloc] init];
NSURL *url=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
parser=[[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser parse];
NSLog(@"testing12 %@ ",url);
// NSLog(@"tweets %@ ", xmlbanktransfer);
NSLog(@"Total values = %d",[xmlbanktransfer count]);
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"item"])
{
currentTweet = [trans alloc];
banktransNodeContent =[[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"date"])
{
currentTweet.date = [currentTweet.date stringByReplacingOccurrencesOfString:@"&" withString:@" "];
currentTweet.date = banktransNodeContent;
}
if([elementName isEqualToString:@"name"])
{
currentTweet.name =banktransNodeContent;
}
if ([elementName isEqualToString:@"type"])
{
currentTweet.type=banktransNodeContent;
}
if ([elementName isEqualToString:@"gross"])
{
currentTweet.gross=banktransNodeContent;
}
if ([elementName isEqualToString:@"fee"])
{
currentTweet.fee=banktransNodeContent;
}
if ([elementName isEqualToString:@"net"])
{
currentTweet.net=banktransNodeContent;
NSLog(@"current tweet %@",currentTweet.net);
}
if ([elementName isEqualToString:@"category"])
{
currentTweet.category=banktransNodeContent;
NSLog(@"current tweet %@",currentTweet.category);
}
if ([elementName isEqualToString:@"account"])
{
currentTweet.account=banktransNodeContent;
NSLog(@"current tweet %@",currentTweet.account);
}
if([elementName isEqualToString:@"item"])
{
[xmlbanktransfer addObject:currentTweet];
currentTweet = nil;
banktransNodeContent = nil;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(@"currentNodeContent are %@",banktransNodeContent);
banktransNodeContent = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"currentNodeContentstring test are %@",banktransNodeContent);
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
banktransNodeContent = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
}