将图像传递给iOS中的滑块
问题描述:
我制作了一个自定义表格视图,其中有一些标签和图像视图,其中数据来自服务并进一步传递到新视图控制器以获取数据的详细信息。单击单元格时,将来自特定单元格的数据传递给新的vc,并在其中显示其详细信息。当新的vc打开一个叫做服务的服务时,所有的图像都会在新的vc中显示出来。而且我使用了图像滑块来显示来自该滑块中服务的所有图像。我已经使用这个滑块enter link description here,最初我使用了一些静态图像,而不是我将图像数组传递给sider,但我不知道为什么图像没有进入滑块。我的代码是,将图像传递给iOS中的滑块
-(void)loadCustomerRecords
{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
NSString *string1 = _propid.text;
NSLog(@"ID is %@",string1);
NSString *[email protected]"My URL";
NSString *string3 = [urll stringByAppendingString:string1];
NSURL * url = [NSURL URLWithString:string3];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
NSString *parameters = [NSString stringWithFormat:@"%@",@"HI"];
NSLog(@"parameter %@",parameters);
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSLog(@"MY Response %@ ", dictionary);
NSArray *results = [dictionary objectForKey:@"property_images"];
NSLog(@"RESULT %@ ", results);
for (NSDictionary * oneCustomer in results)
{
// Create a new Customer record
StringData * newCustomer = [[StringData alloc] init];
newCustomer.images = [oneCustomer objectForKey:@"name"];
NSLog(@"IMAGE: %@ ", newCustomer.images);
[_Image1 addObject:newCustomer];
NSString *imageURL = @"http://www.pk.house/frontend/propertyimages/";
NSString *string3 = [imageURL stringByAppendingString:newCustomer.images];
newCustomer.images = string3;
NSLog(@"Image URL %@",string3);
// [_Image1 addObject:[oneCustomer objectForKey:@"name"]];
//NSLog(@"Array %@",_Image1);
}
dispatch_async(dispatch_get_main_queue(), ^{
// This code will run once the JSON-loading section above has completed.
});
NSString *status=[dictionary valueForKey:@"property_images"];
NSLog(@"Status:%@",status);
}
else{
NSLog(@"network error:");
}
}];
[dataTask resume];
}
答
你从哪里初始化了_Image1数组?并且您没有将更新后的字符串添加到数组中。
试试这个:
-(void)loadCustomerRecords
{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
NSString *string1 = _propid.text;
NSLog(@"ID is %@",string1);
NSString *[email protected]"My URL";
NSString *string3 = [urll stringByAppendingString:string1];
NSURL * url = [NSURL URLWithString:string3];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
NSMutableArray *_Image1 = [NSMutableArray new];
NSString *parameters = [NSString stringWithFormat:@"%@",@"HI"];
NSLog(@"parameter %@",parameters);
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSLog(@"MY Response %@ ", dictionary);
NSArray *results = [dictionary objectForKey:@"property_images"];
NSLog(@"RESULT %@ ", results);
for (NSDictionary * oneCustomer in results)
{
// Create a new Customer record
StringData * newCustomer = [[StringData alloc] init];
NSString *imageURL = @"http://www.pk.house/frontend/propertyimages/";
NSString *string3 = [imageURL stringByAppendingString:[oneCustomer objectForKey:@"name"]];
newCustomer.images = string3;
[_Image1 addObject:newCustomer];
NSLog(@"Image URL %@",string3);
// [_Image1 addObject:[oneCustomer objectForKey:@"name"]];
//NSLog(@"Array %@",_Image1);
}
dispatch_async(dispatch_get_main_queue(), ^{
// This code will run once the JSON-loading section above has completed.
NSLog(@"Array of images :%@",_Image1);
});
NSString *status=[dictionary valueForKey:@"property_images"];
NSLog(@"Status:%@",status);
}
else{
NSLog(@"network error:");
}
}];
[dataTask resume];
}
+0
评论不适合长时间讨论;这个对话已经[转移到聊天](http://chat.stackoverflow.com/rooms/150441/discussion-on-answer-by-anand-kore-pass-arrays-of-images-to-a-slider-在-IOS)。 –
您的代码似乎是建立网址的数组。我不明白与将数据传递给视图控制器的问题有什么关系。 –
实际上数据是通过segue传递的,当任何单元格被点击时,它将数据传递给新的vc,同时一个函数被载入,我上面用loadCustomerRecords这个名字写出了这个函数。阵列是空的,我不知道为什么,但响应来自控制台中的服务正确。 @PhillipMills –
我认为你只是将图像名称添加到数组中,然后将其附加到基本URL。 –