简体   繁体   中英

On selecting the table cell “didSelect” how to parse images to another View?

I'm getting the fellowing response from the web service and using AFNetworking in my Application

{
"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"
}
}

Table Configuration in 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

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

     }

For Static images it's working fine , but for the web service it's not working.. can anyone say where exactly i'm going wrong?

update your method to:

 -(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];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM