2011-02-25 48 views
4

我是新的iphone開發,我想加載一個NSMutableArray值到一個表視圖,我使用下面的代碼爲此生成錯誤,如指定。有人能幫我糾正這個錯誤嗎?在將表格視圖加載NSMutablearray值時出現問題?

代碼: -

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [ShowList count]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    NSString *cellValue = [ShowList objectAtIndex:indexPath.row]; 
    cell.textLabel.text = cellValue; 
    return cell; 

} 

錯誤: -

2011-02-25 07:22:24.470 iPhone[1032:207] -[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0xab15d30 
2011-02-25 07:22:24.471 iPhone[1032:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0xab15d30' 
*** Call stack at first throw: 

我的NSMutableArray的打印說明: -

2011-02-25 07:21:54.806[1032:207] (
     (
     "viral_tweeter", 
     default1571546, 
     default1570056, 
     twilightsaga, 
     "wp-monetizer", 
     viraltweetbuild, 
     "building_a_list", 
     yourtwittertips, 
     "twitter_profit", 
     mikesbi, 
     mikesbizz, 
     default1164341, 
     incbizztest, 
     default1164319, 
     iprotv, 
     iwantafreecopy1, 
     tweeterbuilder, 
     trafficlists, 
     myadsensenews, 
     mysafelistnews, 
     myviralnews, 
     safelistology, 
     slmembers, 
     slpmembers, 
     twonderlandlist, 
     noseospider, 
     yseospider, 
     digitallockdown, 
     alistblueprint, 
     classifiedtips, 
     incbizzblog, 
     "xit-trafficbeta", 
     twwidget, 
     jvtrafficfunnel, 
     instantmlmspage, 
     listbuldingmax, 
     "incbizz_tips" 
    ) 
) 

解析HTTP GET響應代碼: -

- (void)requestDataFetcher:(GTMHTTPFetcher *)fetcher finishedWithData:(NSData *)data error:(NSError *)error { 

    // this is only for testing whether the data is coming or not 
    // NSDictionary *tempDict = [GTMOAuthAuthentication dictionaryWithResponseData:data]; 

    if (error) 
    { 
     NSLog(@"Error: in getting data after authentication : %@",[error description]); 
    } 

    else 
    { 
     // NSLog(@"Succcess: in getting data after authentication \n data: %@",[tempDict description]); 
     NSString* aStr; 
     aStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; 
     NSDictionary *dictionary = [aStr JSONValue]; 
     NSArray *keys = [dictionary allKeys]; 
     Names = [[NSMutableArray alloc]init]; 
     int i = 0; 
     // values in foreach loop 
     for (NSString *key in keys) 
     { 
      i++; 
      NSArray *items = (NSArray *) [dictionary objectForKey:key]; 
      // NSLog(@" test %@", items); 
      if (i==3) 
      { 
       for (NSString *item in items) 
       { 
        NSString* aStrs= item; 
        // NSLog(@" test %@", aStrs); 

        NSDictionary *dict = aStrs; 
        NSArray *k = [dict allKeys]; 
        for (id *it in k) 
        { 
         // NSLog(@"the child item: %@", [NSString stringWithFormat:@"Child Item -> %@ value %@", (NSDictionary *) it,[dict objectForKey:it]]); 
         NSString *value = [it description]; 
         if ([value isEqualToString:@"name"]) 
         { 
          NSString * value = (NSString*)[[dict objectForKey:it] description]; 
          NSLog(value); 
          [Names addObject:value]; 
          [[MySingletonClass sharedMySingleton] SetAweberList: value]; 
         } 
        } 
       } 
      } 
     } 


     mShowList.hidden = FALSE; 
    } 

} 

回答

3

@Ravi你的數組是數組是ShowList的陣列是具有第一對象數組的數組,數組是

"viral_tweeter", 
    default1571546, 
    default1570056, 
    twilightsaga, 
    "wp-monetizer", 
    viraltweetbuild, 
    "building_a_list", 
    yourtwittertips, 
    "twitter_profit", 
    mikesbi, 
    mikesbizz, 
    default1164341, 
    incbizztest, 
    default1164319, 
    iprotv, 
    iwantafreecopy1, 
    tweeterbuilder, 
    trafficlists, 
    myadsensenews, 
    mysafelistnews, 
    myviralnews, 
    safelistology, 
    slmembers, 
    slpmembers, 
    twonderlandlist, 
    noseospider, 
    yseospider, 
    digitallockdown, 
    alistblueprint, 
    classifiedtips, 
    incbizzblog, 
    "xit-trafficbeta", 
    twwidget, 
    jvtrafficfunnel, 
    instantmlmspage, 
    listbuldingmax, 
    "incbizz_tips" 

所以你可以做這樣的事情。

NSString *cellValue = [[ShowList objectAtIndex:0] objectAtIndex:indexPath.row]; 
+0

您好羅賓我已經做了一些改變,我如何存儲字符串在NSMutableArray現在你的代碼運行,但只有單個單元格填充和數組的說明是相同的沒有改變,我也嘗試更改0與indexPath.row但相同的輸出。 – 2011-02-25 11:02:10

+0

@Ravi我以後會回覆你,我必須回家。 – Robin 2011-02-25 11:39:37

+0

你可以打印'[ShowList objectAtIndex:0]'的值並在你的問題中顯示它。 – Robin 2011-02-26 10:25:57

1

我想UILabelsetText要求isEqualToString出於某種原因,所以它崩潰了您的數組中的第一個對象,它是不是一個NSString

+0

關於如何解決此問題的任何線索。 – 2011-02-25 08:29:28

+0

取決於您實際嘗試在表格中顯示的內容。數組中的這些對象是什麼? – 2011-02-25 08:41:26

+0

請發佈http-get的URL和處理響應的代碼。 – 2011-02-25 10:03:09

相關問題