我製作了一個自定義表格視圖,其中有一些標籤和圖像視圖,其中數據來自服務並進一步傳遞到新視圖控制器以獲取數據的詳細信息。單擊單元格時,將來自特定單元格的數據傳遞給新的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];
}
您的代碼似乎是建立網址的數組。我不明白與將數據傳遞給視圖控制器的問題有什麼關係。 –
實際上數據是通過segue傳遞的,當任何單元格被點擊時,它將數據傳遞給新的vc,同時一個函數被載入,我上面用loadCustomerRecords這個名字寫出了這個函數。陣列是空的,我不知道爲什麼,但響應來自控制檯中的服務正確。 @PhillipMills –
我認爲你只是將圖像名稱添加到數組中,然後將其附加到基本URL。 –