從昨天開始,我就遇到了非常小的問題。我在數據庫中有兩個表,其中有Projects和其他Benefits。我想在單PickerView組件中添加這兩個表數據。例如項目有pro1,proj2,proj3和Benefits表有益處1,好處2。所以我想在一個PickerView組件中追加兩個項目table dat和Benefits表格數據。在UIPickerView中的單個組件中追加兩個組件
-(void)loadprojects
{
NSString *post =[[NSString alloc] initWithFormat:@"username=%@",[self.projectpicker dataSource]];
// Code for Project loading
NSString * BenefitString [email protected]"http://test.com/GetBenefitTypes";
NSURL *Benefiturl = [NSURL URLWithString:BenefitString];
NSString *projecturltemp = @"http://test.com/GetAssignedProjects";
NSString *str = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserLoginIdSession"];
NSString *usrid = str;
NSString * projecturl =[NSString stringWithFormat:@"%@/%@",projecturltemp,usrid];
NSURL *url = [NSURL URLWithString:projecturl];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:Benefiturl];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/projectpicker" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/jsonArray" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
NSURLRequest *urlRequestBenifits = [NSURLRequest requestWithURL:Benefiturl
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
urlData = [NSURLConnection sendSynchronousRequest:urlRequestBenifits
returningResponse:&response
error:&error];
if ([response statusCode] >= 200 && [response statusCode] < 300)
{
NSString *responseData = [NSJSONSerialization JSONObjectWithData:urlData
options:NSJSONReadingAllowFragments error:&error];
NSArray *entries = [NSJSONSerialization JSONObjectWithData:[responseData dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&error];
if(!entries)
{
NSLog(@"Error : %@", error);
}
else{
for (NSDictionary *entry in entries) {
projID = [entries valueForKey:@"ID_PROJECT"];
projectNames = [entries valueForKey:@"NM_PROJECT"];
BenefitsNames = [entries valueForKey:@"NM_LEAVES"];
}
//Combined = [BenefitsNames arrayByAddingObjectsFromArray:projectNames];
NSLog(@"Combined : %@", projectNames);
//NSLog(@"projID : %@", projID);
_projectpicker.delegate = self;
_projectpicker.dataSource = self;
}
} else {
}
}
爲什麼不使用2個組件?你到目前爲止嘗試了什麼?什麼沒有用? – Wain
我在我的pickerview中有三個組件,我想在1個組件中添加這個配置和項目。 – user3401290
我能夠加載所有組件中的所有數據,但我希望將此優點添加到組件中的項目組件1 – user3401290