從Picker視圖中選擇數據時,我得到了我的項目ID:12。現在我的問題是我想將這12(項目ID)發送到NSURL,以便在更改項目時分別加載我的任務。這裏是我下面的代碼:將Pickerview數據發送到URL
viewDidLoad中:
NSString *nsTaskurllocal = @"http://xxxx/xxx/";
NSString *projectsLabel = [self.lblProjects text];
NSString *aString = [nsTaskurllocal stringByAppendingString:projectsLabel];
NSLog(@"aString : %@", aString);
NSString *temp = [aString stringByAppendingString:@"/"];
int usrid = 313;
NSString *usridstring = [NSString stringWithFormat:@"%d", usrid];
NSString *finalurl = [usridstring stringByAppendingString:temp];
NSURL *nstaskurl = [NSURL URLWithString:finalurl];
NSLog(@"nstaskurl : %@", nstaskurl);
NSData *nstaskpostData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *nstaskpostLength = [NSString stringWithFormat:@"%lu", (unsigned long)[nstaskpostData length]];
NSMutableURLRequest *nstaskrequest = [[NSMutableURLRequest alloc] init];
[request setURL:nstaskurl];
[request setHTTPMethod:@"POST"];
[request setValue:nstaskpostLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/projectpicker" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/jsonArray" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:nstaskpostData];
NSError *nstaskerror = [[NSError alloc] init];
NSHTTPURLResponse *nstaskresponse = nil;
NSData *nstaskurlData=[NSURLConnection sendSynchronousRequest:nstaskrequest returningResponse:&nstaskresponse error:&nstaskerror];
NSURLRequest *nstaskurlRequest = [NSURLRequest requestWithURL:nstaskurl
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Make synchronous request
nstaskurlData = [NSURLConnection sendSynchronousRequest:nstaskurlRequest
returningResponse:&nstaskresponse
error:&nstaskerror];
if ([nstaskresponse statusCode] >= 200 && [nstaskresponse statusCode] < 300)
{
NSString *nstaskresponseData = [NSJSONSerialization JSONObjectWithData:nstaskurlData
options:NSJSONReadingAllowFragments error:&nstaskerror];
NSArray *nstaskentries = [NSJSONSerialization JSONObjectWithData:[nstaskresponseData dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&nstaskerror];
if(!nstaskentries)
{
NSLog(@"Error : %@", nstaskerror);
}
else{
for (NSDictionary *nstaskentry in nstaskentries) {
taskID = [nstaskentries valueForKey:@"ID_TASK"];
taskNames = [nstaskentries valueForKey:@"TASk_NAME"];
//NSLog(@"Error : %@", taskNames); //log to see the result in console // by Kiran
}
_projectpicker.delegate = self;
_projectpicker.dataSource = self;
}
} else {
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSNumber *myProjectArrayString = [projID objectAtIndex:row];
//NSNumber *myTaskArrayString = [taskID objectAtIndex:row];
//NSLog(@"%@",myArrayString);
//NSLog(@"%@",myTaskArrayString);
lblProjects.text = [NSString stringWithFormat:@"%@",myProjectArrayString];
//lblProjects.hidden = YES;
lblTasks.text = [taskNames objectAtIndex:[pickerView selectedRowInComponent:1]];
//lblTasks.text = [NSString stringWithFormat:@"%@", myTaskArrayString];
lblSubTasks.text = [subtaskNames objectAtIndex:[pickerView selectedRowInComponent:2]];
}
lblProjects.text有項目編號:12,所以我需要這個12傳遞給我的ASTRING,這樣我可以追加和它傳遞給NSURL Thnaks
你想在服務機身右側發送信息(12)? –
即12是動態ID。在這裏,用戶從選擇器視圖中選擇一個數據,並根據選擇的ID加載到標籤中,並且需要發送到NSURL,以便它可以分別加載任務項目選擇.. –
你能告訴我你的最終結果網址看起來像。我想http:// xxxx/xxx/userID/projectId ...請讓我知道 –