[英]JSON data show on first cell
我正在开发一个IOS App。在按钮上单击在Tableview中显示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;
}
我认为您在numberOfRowsInSection:
方法中返回错误的行数。
将return语句更改为
return [[str objectForKey:@"results"] count];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.