NSDictionary для NSArray и обратно в NSDictionary - PullRequest
0 голосов
/ 19 ноября 2011

Я пытаюсь показать комментарии с disqus.com в моем UITableView.

Теперь у меня есть: 1.

//Creating NSArray with comments only from NSDictionary Dict
    comments = [dict objectForKey:@"response"];
            NSLog(@"MessageArray:%@ count:%i", comments, [comments count]);
            [tableViewNew reloadData];

2

//I'm trying to get NSDictionary from NSArray, but it isn't work
NSDictionary *currentComment = [comments objectAtIndex:indexPath.row];
//currentComment = nil

В моем * .h файле у меня есть это:

NSArray* comments;
@property (retain, nonatomic) NSArray* comments;

И текст моего комментария:

(
        {
        author =         {
            about = "";
            avatar =             {
                cache = "http://mediacdn.disqus.com/1321567697/images/noavatar92.png";
                permalink = "http://disqus.com/api/users/avatars/itruf.jpg";
            };
            emailHash = 7741f7b9bbf2a05ff782550412b9a513;
            id = 16898031;
            isAnonymous = 0;
            joinedAt = "2011-09-17T17:17:16";
            name = itruf;
            profileUrl = "http://disqus.com/itruf/";
            url = "";
            username = itruf;
        };
        createdAt = "2011-11-19T06:28:28";
        dislikes = 0;
        forum = smartfiction;
        id = 368112946;
        isApproved = 1;
        isDeleted = 0;
        isEdited = 0;
        isFlagged = 0;
        isHighlighted = 0;
        isJuliaFlagged = 1;
        isSpam = 0;
        likes = 0;
        media =         (
        );
        message = "\U0422\U0435\U0441\U0442. \U041f\U0440\U043e\U0448\U0443 \U043d\U0435 \U0433\U043d\U0435\U0432\U0430\U0442\U044c\U0441\U044f.<br><br><br><br>!!!!!!<br><br>\U0410\U0430 \U0411\U0431 \U0412\U0432 \U0413\U0433 \U0414\U0434 \U0415\U0435 \U0401\U0451 \U0416\U0436 \U0417\U0437 \U0418\U0438 \U0419\U0439 \U041a\U043a \U041b\U043b \U041c\U043c \U041d\U043d \U041e\U043e \U041f\U043f \U0420\U0440 \U0421\U0441 \U0422\U0442 \U0423\U0443 \U0424\U0444 \U0425\U0445 \U0426\U0446 \U0427\U0447 \U0428\U0448 \U0429\U0449 \U042a\U044a \U042b\U044b \U042c\U044c \U042d\U044d \U042e\U044e \U042f\U044f";
        parent = "<null>";
        points = 0;
        "raw_message" = "\U0422\U0435\U0441\U0442. \U041f\U0440\U043e\U0448\U0443 \U043d\U0435 \U0433\U043d\U0435\U0432\U0430\U0442\U044c\U0441\U044f.\n\n\n\n!!!!!!\n\n\U0410\U0430 \U0411\U0431 \U0412\U0432 \U0413\U0433 \U0414\U0434 \U0415\U0435 \U0401\U0451 \U0416\U0436 \U0417\U0437 \U0418\U0438 \U0419\U0439 \U041a\U043a \U041b\U043b \U041c\U043c \U041d\U043d \U041e\U043e \U041f\U043f \U0420\U0440 \U0421\U0441 \U0422\U0442 \U0423\U0443 \U0424\U0444 \U0425\U0445 \U0426\U0446 \U0427\U0447 \U0428\U0448 \U0429\U0449 \U042a\U044a \U042b\U044b \U042c\U044c \U042d\U044d \U042e\U044e \U042f\U044f";
        thread = 475714714;
    },
        {
        author =         {
            avatar =             {
                cache = "http://www.gravatar.com/avatar.php?gravatar_id=2c5d4ef0caae2eb294f9f85cff0fa88b&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
                permalink = "http://www.gravatar.com/avatar.php?gravatar_id=2c5d4ef0caae2eb294f9f85cff0fa88b&size=32&default=http://mediacdn.disqus.com/1321567697/images/noavatar32.png";
            };
            emailHash = 2c5d4ef0caae2eb294f9f85cff0fa88b;
            isAnonymous = 1;
            name = "\U0421\U0435\U0440\U0433\U0435\U0439";
            profileUrl = "http://disqus.com/guest/2c5d4ef0caae2eb294f9f85cff0fa88b/";
            url = "";
        };
        createdAt = "2011-11-18T07:36:47";
        dislikes = 0;
        forum = smartfiction;
        id = 367328215;
        isApproved = 1;
        isDeleted = 0;
        isEdited = 0;
        isFlagged = 0;
        isHighlighted = 0;
        isJuliaFlagged = 1;
        isSpam = 0;
        likes = 1;
        media =         (
        );
        message = "\U041a\U043b\U0430\U0441\U0441!!! \U0420\U0430\U0431\U043e\U0447\U0438\U0439 \U043a\U043e\U043c\U0430\U043d\U0434\U0443\U0435\U0442 \U043c\U0435\U043d\U0435\U0434\U0436\U0435\U0440\U043e\U043c! \U0414\U0430 \U043a\U0430\U043a \U0433\U0440\U0430\U043c\U043e\U0442\U043d\U043e \U043e\U043d \U044d\U0442\U043e \U0434\U0435\U043b\U0430\U0435\U0442! \U0410 \U043c\U0438\U0441\U0442\U0435\U0440 \U0413\U0440\U0438\U043c\U043c\U0435\U0442, \U043f\U043e\U0445\U043e\U0436\U0435, \U0438 \U0432\U043f\U0440\U0430\U0432\U0434\U0443 \U0431\U043e\U043b\U0432\U0430\U043d.";
        parent = "<null>";
        points = 1;
        "raw_message" = "\U041a\U043b\U0430\U0441\U0441!!! \U0420\U0430\U0431\U043e\U0447\U0438\U0439 \U043a\U043e\U043c\U0430\U043d\U0434\U0443\U0435\U0442 \U043c\U0435\U043d\U0435\U0434\U0436\U0435\U0440\U043e\U043c! \U0414\U0430 \U043a\U0430\U043a \U0433\U0440\U0430\U043c\U043e\U0442\U043d\U043e \U043e\U043d \U044d\U0442\U043e \U0434\U0435\U043b\U0430\U0435\U0442! \U0410 \U043c\U0438\U0441\U0442\U0435\U0440 \U0413\U0440\U0438\U043c\U043c\U0435\U0442, \U043f\U043e\U0445\U043e\U0436\U0435, \U0438 \U0432\U043f\U0440\U0430\U0432\U0434\U0443 \U0431\U043e\U043b\U0432\U0430\U043d.";
        thread = 475714714;
    }
)

Я хочу иметь NSDictionary со всеми ключами из моего массива. Большое спасибо.

1 Ответ

0 голосов
/ 20 декабря 2011

Вы можете попробовать это:

    NSDictionary *currentComment = [[NSDictionary alloc] initWithDictionary: [comments objectAtIndex:indexPath.row]];

Я думаю, что вы используете это в своем методе "cellForRowAtIndex" ... Так что если да, то прежде чем возвращать YES в ячейку, наконец, этого метода освободите словарь. В противном случае это может привести к ошибке или неправильным данным. Счастливое кодирование:)

...