gpt4 book ai didi

ios - 在选择表格单元格 "didSelect"时如何将图像解析到另一个 View ?

转载 作者:行者123 更新时间:2023-11-29 02:40:01 24 4
gpt4 key购买 nike

我正在从 Web 服务获取相关响应并在我的应用程序中使用 AFNetworking

{
"CityMap_Image":
{"
ImagePath1":"alm.demo11.com\/admin\/AlMithaqImages\/24378070-98a4-4d05-9306-d17b0c6c58c9.jpg",
"ImagePath2":"alm.demo11.com\/admin\/AlMithaqImages\/ad9f24f9-ca58-4c73-8289-161b5d5bd16d.jpg"
}
}

主视图中的表配置

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CityDetailViewController * cityMap = [[CityDetailViewController alloc]initWithNibName:@"CityDetailViewController" bundle:nil];

if (tableView == stage3menuTableView) {

if (indexPath.row == 0) {


[self.navigationController pushViewController:cityMap animated:NO];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://alm.demo11.com/API.svc/get_CityMap" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

self.nDic = (NSDictionary *)responseObject;
NSMutableDictionary *nDic1 = [[NSMutableDictionary alloc]initWithDictionary:[self.nDic objectForKey:@"CityMap_Image"]];
NSString *img = [NSString stringWithFormat:@"http://%@",[nDic1 objectForKey:@"ImagePath1"]];
NSURL *url = [NSURL URLWithString:img];
NSData *data = [NSData dataWithContentsOfURL:url];

cityMap.passedImage = [UIImage imageWithData:data];
NSLog(@"response dateJSON: %@", cityMap.passedImage);


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *erroralert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Sorry, Server is not responding. Please try later" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[erroralert show];

}];



}


else if (indexPath.row == 1)
{

[self.navigationController pushViewController:cityMap animated:NO];
cityMap.passedImage = [UIImage imageNamed:@"morebg.png"];


}else
{

[self.navigationController pushViewController:cityMap animated:NO];
cityMap.passedImage = [UIImage imageNamed:@"morebg.png"];

}
[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

第二 View

.h

@interface DetailViewController : UIViewController<UIScrollViewDelegate>
{
IBOutlet UIImageView *bandImage;
}

@property (strong, nonatomic) UIImageView *bandImage;
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) UIImage *passedImage;

@end

.m

-(Void)ViewDidLoad
{
bandImage.image = self.passedImage;

}

对于静态图像它工作正常,但对于网络服务它不工作..谁能说出我到底哪里出错了?

最佳答案

将您的方法更新为:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CityDetailViewController * cityMap = [[CityDetailViewController alloc]initWithNibName:@"CityDetailViewController" bundle:nil];

if (tableView == stage3menuTableView) {

if (indexPath.row == 0) {



AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://alm.demo11.com/API.svc/get_CityMap" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

self.nDic = (NSDictionary *)responseObject;
NSMutableDictionary *nDic1 = [[NSMutableDictionary alloc]initWithDictionary:[self.nDic objectForKey:@"CityMap_Image"]];
NSString *img = [NSString stringWithFormat:@"http://%@",[nDic1 objectForKey:@"ImagePath1"]];
NSURL *url = [NSURL URLWithString:img];
NSData *data = [NSData dataWithContentsOfURL:url];

cityMap.passedImage = [UIImage imageWithData:data];
[self.navigationController pushViewController:cityMap animated:NO];
NSLog(@"response dateJSON: %@", cityMap.passedImage);


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *erroralert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Sorry, Server is not responding. Please try later" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[erroralert show];

}];



}


else if (indexPath.row == 1)
{


cityMap.passedImage = [UIImage imageNamed:@"morebg.png"];
[self.navigationController pushViewController:cityMap animated:NO];


}else
{


cityMap.passedImage = [UIImage imageNamed:@"morebg.png"];
[self.navigationController pushViewController:cityMap animated:NO];

}
[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

关于ios - 在选择表格单元格 "didSelect"时如何将图像解析到另一个 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25909754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com