При выборе ячейки таблицы "didSelect", как анализировать изображения в другом представлении?
Я получаю ответ от веб-службы и использую 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"
}
}
Конфигурация таблицы в MainView
-(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];
}
SecondView
.час
@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;
}
Для статических изображений это работает нормально, но для веб-сервиса это не работает.. кто-нибудь может сказать, где именно я ошибаюсь?
1 ответ
Решение
Обновите свой метод, чтобы:
-(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];
}