2015-03-31 53 views
0

我正在開發一個IOS App.On按鈕單擊顯示JSON數據在Tableview..But數據顯示ON只有第一個單元格不在其他單元格..我可以通過NSLog檢查數據是否正確..但在泰伯維顯示在第一細胞和一些時間應用崩潰,錯誤數據參數都在這條線上JSON數據在第一個單元格上顯示

`"Incompatible Pointer Assigning To 'NSDictionary' 

Nil..Warning顯示要

NSArray "[str = [BBServerJson sendPostRequest:json toUrl:url];]` 

任何幫助或建議是極大的讚賞。提前致謝。

//Button Click 
    BBAuthorViewController *BBAuthor =[[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"BBAuthor"]; 
     BBAuthor.authorDetail=_adDetailsObj.authorDetail; 
     [self.navigationController pushViewController:BBAuthor animated:YES]; 


    //Json 
    +(NSDictionary *)sendPostRequest:(NSDictionary *)params toUrl:(NSString *)urlString 
{ 
    NSMutableString *paramString = 
    [NSMutableString stringWithString:@""]; 
    NSArray *keys = [params allKeys]; 
    for (NSString *key in keys) { 
     [paramString appendFormat:@"%@=%@&",key, 
     [params valueForKey:key]]; 
    } 
    NSString *postString = @""; 
    if ([paramString length] > 0) 
     postString = [paramString substringToIndex: 
         [paramString length]-1]; 
    NSMutableURLRequest *request =[NSMutableURLRequest 
            requestWithURL:[NSURL URLWithString:urlString]]; 
    [request setHTTPMethod:@"POST"]; 
    [request setHTTPBody:[postString 
          dataUsingEncoding:NSUTF8StringEncoding]]; 
    NSURLResponse *res; 
    NSError *error; 
    NSData *resp = [NSURLConnection sendSynchronousRequest:request 
             returningResponse:&res error: 
        &error]; 


    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)res; 

    int statusCode; 
    statusCode = [httpResponse statusCode]; 

    NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:resp options:NSJSONReadingMutableContainers error:&error]; 

    return jsonArray; 
}  



    NSString *url = @"https://boatbrat.com/wp-app-handler-boatsales.php"; 
     NSMutableDictionary *json = [[NSMutableDictionary alloc]init]; 
     [json setObject:@"AuthorListing" forKey:@"method"]; 
     [json setObject:_authorDetail forKey:@"author"]; 
     str = [BBServerJson sendPostRequest:json toUrl:url]; 

    //Tableview 


    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return str.count; 
    } 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    { 
     cell=[tableView dequeueReusableCellWithIdentifier:@"cell"]; 
     NSArray *array = [str objectForKey:@"results"]; 
     NSDictionary *dic= [array objectAtIndex:indexPath.row]; 
     cell.textLabel.text = [dic objectForKey:@"author_name"]; 
     return cell; 
    } 
+0

行數'str.count'?或者'[str objectForKey:@「results」]。count'? – 2015-03-31 12:39:45

回答

0

我認爲你在numberOfRowsInSection:方法中返回錯誤的行數。

更改return語句,

return [[str objectForKey:@"results"] count]; 
相關問題