0

すでに多くの試みを行っていますが、NSArrayからUILabelにアイテムを正しく表示できません。

アレイをNSLogすると、コンソールから次のように返されます。

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

これは、私がWebサイトから取得し、解析した値などです。

問題は、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 に答える