2012-03-26 4 views
0

SBJsonParser를 사용하여 트위터 피드를 가져 오는 튜토리얼을 따라 가려하고 테이블보기로 표시합니다. 내[__NSCFDictionary isEqualToString :] : 인스턴스로 전송 된 인식 할 수없는 선택기 0x6b7e510 '

@interface에 NSString *json_string; NSArray *statusArray;

이 트위터를 얻기 위해 사용하는 코드 메신저 뭐죠

그러나 나는 다음과 같은 오류를 얻고 것은

[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x6b7e510

입니다 피드

0 12,351,742,

그리고 이것은 무엇 테이블보기에 넣어 사용하는 메신저

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 


cell.textLabel.text = [[statusArray objectAtIndex:indexPath.row] objectForKey:@"user"]; 

return cell; 
} 

편집 :

내가 objectatindex와 statusArray을 NSLogged : 0 내가

{ 
contributors = "<null>"; 
coordinates = "<null>"; 
"created_at" = "Mon Mar 26 19:43:54 +0000 2012"; 
favorited = 0; 
geo = "<null>"; 
id = 184365079062528000; 
"id_str" = 184365079062528000; 
"in_reply_to_screen_name" = "<null>"; 
"in_reply_to_status_id" = "<null>"; 
"in_reply_to_status_id_str" = "<null>"; 
"in_reply_to_user_id" = "<null>"; 
"in_reply_to_user_id_str" = "<null>"; 
place = "<null>"; 
"retweet_count" = 0; 
retweeted = 0; 
source = "<a href=\"http://blackberry.com/twitter\" rel=\"nofollow\">Twitter for BlackBerry\U00ae</a>"; 
text = "Kalau tidur jam segini engga mungkin bisa mimpi-___-"; 
truncated = 0; 
user =  { 
    "contributors_enabled" = 0; 
    "created_at" = "Tue Apr 27 18:28:24 +0000 2010"; 
    "default_profile" = 0; 
    "default_profile_image" = 0; 
    description = "27June!"; 
    "favourites_count" = 0; 
    "follow_request_sent" = "<null>"; 
    "followers_count" = 733; 
    following = "<null>"; 
    "friends_count" = 331; 
    "geo_enabled" = 1; 
    id = 137772903; 
    "id_str" = 137772903; 
    "is_translator" = 0; 
    lang = en; 
    "listed_count" = 0; 
    location = ""; 
    name = "Faisal Maulana \U2606"; 
    notifications = "<null>"; 
    "profile_background_color" = 050505; 
    "profile_background_image_url" = "http://a0.twimg.com/profile_background_images/451260814/428031_258048570950875_100002372012794_560610_1320195241_n.jpg"; 
    "profile_background_image_url_https" = "https://si0.twimg.com/profile_background_images/451260814/428031_258048570950875_100002372012794_560610_1320195241_n.jpg"; 
    "profile_background_tile" = 1; 
    "profile_image_url" = "http://a0.twimg.com/profile_images/1962687246/IMG01822-20120319-1126_normal.jpg"; 
    "profile_image_url_https" = "https://si0.twimg.com/profile_images/1962687246/IMG01822-20120319-1126_normal.jpg"; 
    "profile_link_color" = 0a0a0a; 
    "profile_sidebar_border_color" = 161717; 
    "profile_sidebar_fill_color" = ffffff; 
    "profile_text_color" = 050505; 
    "profile_use_background_image" = 1; 
    protected = 0; 
    "screen_name" = IcalHuba; 
    "show_all_inline_media" = 0; 
    "statuses_count" = 60850; 
    "time_zone" = Greenland; 
    url = "<null>"; 
    "utc_offset" = "-10800"; 
    verified = 0; 
}; 

}

있어
+1

JSON 구문 분석기가 자동 렌더링 된 객체를 반환하기 때문에 statusArray가 범위 끝에서 할당 해제됩니다. - 그것을 유지하십시오. –

+0

그러나 ARC는 보유를 금지합니까? – Huntaz556

+0

statusArray 또는 해당 없음을 가져 오시겠습니까? statusArray의 가치를 보여줄 수 있습니까? –

답변

3

json 파서에 버그가 없다고 가정합니다.

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {  
     return 1 
} 

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath 
{ 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

     //note: valueForKeyPath return nil, if key does not find 
     NSString *userInfo = [[statusArray objectAtIndex:indexPath.row] valueForKeyPath:@"user.name"]; // or valueForKeyPath:@"user.screen_name" 

     if ([userInfo [email protected]""] || [userInfo length]<0]) 
      cell.textLabel.text = @"There is no user info"; 
     else 
      cell.textLabel.text = userInfo; 
     return cell; 
} 
0

"사용자"경로가 사전이므로 문자열이 필요합니다. 당신이 문자열을 기대하고있다 레이블의 텍스트 속성에 그 사전을 할당하려고 할 때 오류가 발생 있도록 받고있는 JSON에서

cell.textLabel.text = [[statusArray objectAtIndex:indexPath.row] objectForKeyPath:@"user.name"]; 
1

, 키 "사용자"에 대한 개체는 사전입니다 . 다음과 같이해야합니다 :

cell.textLabel.text = [[[statusArray objectAtIndex:indexPath.row] 
          objectForKey:@"user"] 
          objectForKey:@"screen_name"]; 
관련 문제