JSON数据显示在第一个单元格上

时间:2015-03-31 12:06:39

标签: ios json

我正在开发一个IOS App.On按钮单击在表视图中显示JSON数据..但是数据显示仅在第一个单元格上没有在其他单元格上...我可以通过NSLog检查数据是否正确..但在Tableview中显示在第一个单元格和一些时间应用程序崩溃和错误数据参数是无线。警告显示在这一行

`"Incompatible Pointer Assigning To 'NSDictionary'

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;
    }

1 个答案:

答案 0 :(得分:0)

我认为你在numberOfRowsInSection:方法中返回了错误的行数。

将return语句更改为,

return [[str objectForKey:@"results"] count];