0

尽管我已经做了很多尝试..我无法将 NSArray 中的项目正确显示到 UILabel 中..

当我 NSLog 数组时,控制台会返回这个:

2013-01-19 14:34:32.799 bloom[2766:c07] (
"0.877"
)

这是我从网站获取并解析等的值。

问题是,当我在 UILabel 中显示它时,它显示的内容完全相同,我只需要显示不带引号的值。这是它的显示方式:

显示问题

编辑:

这是我的代码:

- (void)configureView
{
// Update the user interface for the detail item.

if (self.detailItem) {

    for (NSDictionary *valuesDatum in _detailItem) {
        NSDictionary *itemAtIndex = (NSDictionary *)_detailItem;
        self.title = [itemAtIndex objectForKey:@"SYMBOL"];
        NSString *strUrl = @"http://www.bloomberg.com/quote/";
        NSString *ativo = [itemAtIndex objectForKey:@"SYMBOL"];
        NSString *consulta = [strUrl stringByAppendingString:ativo];

        NSURL *url = [NSURL URLWithString:consulta];

        NSData *webData = [NSData dataWithContentsOfURL:url];


        NSString *xPathQuery = @"//span[@class=' price'] | //span[@class=' trending_up  up'] | //span[@class=' trending_up up']/span | //table[@class='snapshot_table']/tr/td";

        TFHpple *parser = [TFHpple hppleWithData:webData isXML:NO];

        NSArray *array = [parser searchWithXPathQuery:xPathQuery];

        valores = [[NSMutableArray alloc]init];
        for (TFHppleElement *element in array) {
            [valores addObject:[[element firstChild] content]];
        }

        novosValores = [[NSMutableArray alloc]init];
        for (NSString *valuesDatum in valores) {
            NSString *removeNewLine = [[valuesDatum componentsSeparatedByCharactersInSet: [NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
            NSString *removeSpace = [removeNewLine stringByReplacingOccurrencesOfString:@"         " withString:@""];
            NSString *removeSpaceOne = [removeSpace  stringByReplacingOccurrencesOfString:@"    " withString:@""];
            NSString *trocaVirgulaPonto = [removeSpaceOne stringByReplacingOccurrencesOfString:@"," withString:@"."];
            [novosValores addObject:trocaVirgulaPonto];
        }

        valoresFinais = [[NSMutableArray alloc]init];
        for (NSString *valuesDatum in novosValores) {
            NSArray *val = [valuesDatum componentsSeparatedByString:@" - "];
            [valoresFinais addObject:val];
        }

        infos = [[NSMutableArray alloc]init];
        for (NSArray *dados in valoresFinais) {
            NSArray *arrayDados = [[NSArray alloc]initWithArray:dados];

            for (NSString *teste in arrayDados) {
                NSArray *arrayTeste = [teste componentsSeparatedByString:@","];
                [infos addObject:arrayTeste];
            }
        }
        NSLog(@"%@",[infos objectAtIndex:0]);

        NSString *fff = [[NSString alloc] initWithFormat:@"%@", [infos objectAtIndex:0]];
        [_detailDescriptionLabel setText:fff];
    }

    }
}

新编辑:

我有这个数组:

2013-01-19 15:43:05.055 bloom[3564:c07] (
"7.730",
"0.020",
"0.26%",
"7.750",
"7.650-7.800",
"2.333.100",
"7.710",
"3.730-8.810",
"+4.04%"

)

我只需要一个新数组,其中第 5 行和第 8 行的数据用“-”分隔。

所以有人有灯吗??

谢谢!!!

4

3 回答 3

1

我在 Anoop 的帮助下解决了这个问题。我改变了一点他的代码,最后我的代码是这样的:

for (NSDictionary *valuesDatum in _detailItem) {
        NSDictionary *itemAtIndex = (NSDictionary *)_detailItem;
        self.title = [itemAtIndex objectForKey:@"SYMBOL"];
        NSString *strUrl = @"http://www.bloomberg.com/quote/";
        NSString *ativo = [itemAtIndex objectForKey:@"SYMBOL"];
        NSString *consulta = [strUrl stringByAppendingString:ativo];

        NSURL *url = [NSURL URLWithString:consulta];

        NSData *webData = [NSData dataWithContentsOfURL:url];

        NSString *xPathQuery = @"//span[@class=' price'] | //span[@class=' trending_up up'] | //span[@class=' trending_up up']/span | //table[@class='snapshot_table']/tr/td";

        TFHpple *parser = [TFHpple hppleWithData:webData isXML:NO];

        NSArray *array = [parser searchWithXPathQuery:xPathQuery];

        valores = [[NSMutableArray alloc]init];
        for (TFHppleElement *element in array) {
            [valores addObject:[[element firstChild] content]];
        }

        novosValores = [[NSMutableArray alloc]init];
        for (NSString *valuesDatum in valores) {
            NSString *removeNewLine = [[valuesDatum componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
            NSString *removeSpace = [removeNewLine stringByReplacingOccurrencesOfString:@"         " withString:@""];
            NSString *removeSpaceOne = [removeSpace stringByReplacingOccurrencesOfString:@"    " withString:@""];
            NSString *removeSpaceTwo = [removeSpaceOne stringByReplacingOccurrencesOfString:@" " withString:@""];
            NSString *removeDash = [removeSpaceTwo stringByReplacingOccurrencesOfString:@" - " withString:@" "];
            NSString *trocaVirgulaPonto = [removeDash stringByReplacingOccurrencesOfString:@"," withString:@"."];

            [novosValores addObject:trocaVirgulaPonto];
        }

        NSString *fullString=[novosValores componentsJoinedByString:@"_"];
        NSString *changeDash = [fullString stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
        finalArray=[changeDash componentsSeparatedByString:@"_"];
        //NSLog(@"%@", finalArray);

    }
    NSString *str = [[NSString alloc]initWithFormat:@"%@",[finalArray objectAtIndex:10]];
    [_detailDescriptionLabel setText:str];
于 2013-01-19T19:19:16.480 回答
0
 (
   "0.877"
)

以上是一个数组,您将该数组放在标签上。

你必须使用someLabel.text=[thatArray objectAtIndex:0];

编辑:

根据您的要求尝试这个:(未检查编译器)

NSString *fullString=[array componentsJoinedByString:@"+"];
NSArray *brokenString=[fullString componentsSeparatedByString:@"-"];
NSString *mainString=brokenString[1];
NSArray *finalArray=[mainString componentsSepartedByString:@"+"];
于 2013-01-19T17:43:09.567 回答
0

你确定你是这样的:

label.text = [array objectAtIndex:0];

代替:

label.text = array;
于 2013-01-19T17:43:49.627 回答