想要在桌面视图中将Webservies图像设置为按钮背景图像
{
"results": {
"results": [
{
"id": "167",
"image": "http: 20141115003645.png", //// set any images
"exercise_name": "Cable Body Weight seated"
}
]
},
"status": "OK"
}
“图像”我得到的图像我想将图像显示为按钮背景... 我怎样才能帮到我!!!!
答案 0 :(得分:0)
NSMutableArray *imagearray=[NSMutableArray new]; // this is your tableArray
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:receivedData options: kNilOptions error:nil]; // your json response started with Dictionary
NSArray *imagekey=[[jsonDict objectForKey:@"results"]objectForKey:@"results"];
for (NSDictionary *tmp in imagekey)
{
NSDictionary *tmpimagekey=[NSMutableDictionary new];
[tmpimagekey setValue:[tmp objectForKey:@"image"] forKey:@"image"];
[imagearray addObject:tmpimagekey];
}
[yourtableName reloadData];
您的cell
方法中的
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// here cell process
NSData * imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@“herpassyourURL /%@”,[[imagearray objectAtIndex:indexPath.row] objectForKey:@“image”]]]]; UIImage * image = [[UIImage alloc] initWithData:imageData];
[yourbuttonName setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
[yourbuttonName addTarget:self action:@selector(imagebuttonclicked) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:yourbuttonName];
return cell;
}
-(void)imagebuttonclicked
{
// do ur stuff
}