0

テーブルビューにカスタムセルがあります。すべての接続が確立されます。Twitterで検索しています。この結果は、tableViewのカスタムセルを伝播します。コンポーネントで区切られた文字列を使用して個々のツイートを配列に分離し、カスタムセルの4つのラベルにこれらを割り当てることができるようにします。どんな助けでも大歓迎です。これが私のコードです。

    - (void)fetchTweets
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSData* data = [NSData dataWithContentsOfURL:
                            [NSURL URLWithString: @"https://api.twitter.com/1/statuses/public_timeline.json"]];

            NSError* error;

            tweets = [NSJSONSerialization JSONObjectWithData:data
                                                     options:kNilOptions
                                                       error:&error];

            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView reloadData];
            });
        });
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return tweets.count;

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"TweetCell";

        customCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
                // added this bit in
            cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


        }

       // THIS IS THE BIT I'M STRUGGLING WITH
// I'M GUESSING THAT THIS LINE SEPARATES THE TWEETS INTO SINGLE TWEETS?
        NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
// I THEN CREATE AN ARRAY TO HOLD MY COMPONENTS OF THE TWEET SO THAT I CAN SPLIT FOR MY LABELS
        NSArray *arrayForCustomCell = [[NSArray alloc] init];

        arrayForCustomCell = [tweet componentsSeparatedByString:@":"];





        return cell;
    }
4

1 に答える 1

1

非同期呼び出しで既に結果を解析しています。これで、'tweet' 辞書の配列ができ、次のように任意の値を取得できます。

NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
NSString *tweetText = [tweet valueForKey:@"text"];
NSString *tweetCountry = [tweet valueForKeyPath:@"place.country"] //Nested property

を設定するだけですUILabels。あなたはアイデアを得る...

于 2012-05-24T13:20:07.197 に答える