我是iOS新手,我遇到了从数组中获取字符串当前值的问题。
我的代码就像这样
loginStatusHS = [[NSString alloc] initWithBytes: [myNSMDatalatetudeFromServer mutableBytes] length:[myNSMDatalatetudeFromServer length] encoding:NSUTF8StringEncoding];
NSLog(@"loginStatus =%@",loginStatusHS);
NSError *parseError = nil;
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:loginStatusHS error:&parseError];
NSLog(@"JSON DICTIONARY = %@",xmlDictionary);
recordResultHS = [xmlDictionary[@"success"] integerValue];
NSLog(@"Success: %ld",(long)recordResultHS);
NSDictionary* Address=[xmlDictionary objectForKey:@"soap:Envelope"];
NSLog(@"Address Dict = %@",Address);
NSDictionary *new =[Address objectForKey:@"soap:Body"];
NSLog(@"NEW DICT =%@",new);
NSDictionary *LoginResponse=[new objectForKey:@"HS_GetResponse"];
NSLog(@"Login Response DICT =%@",LoginResponse);
NSDictionary *LoginResult=[LoginResponse objectForKey:@"HS_GetResult"];
NSLog(@"Login Result =%@",LoginResult);
if(LoginResult.count>0)
{
NSLog(@"Login Result = %@",LoginResult);
NSLog(@"Login Result Dict =%@",LoginResult);
NSString *teststr =[[NSString alloc] init];
teststr =[LoginResult objectForKey:@"text"];
NSLog(@"Test String Value =%@",teststr);
NSString *string = [LoginResult valueForKey:@"text"];
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
responseletetudedict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"Latetude Dictionary =%@",responseletetudedict);
idlatetudearray=[[NSMutableArray alloc]init];
idlatetudearray=[responseletetudedict valueForKey:@"City"];
NameHSArray=[[NSMutableArray alloc] init];
NameHSArray=[responseletetudedict valueForKey:@"Name"];
AddressHSArray=[[NSMutableArray alloc] init];
AddressHSArray=[responseletetudedict valueForKey:@"Address"];
FacilitiesHSArray=[[NSMutableArray alloc] init];
FacilitiesHSArray=[responseletetudedict valueForKey:@"Facilities"];
PhoneNoHSArray=[[NSMutableArray alloc] init];
PhoneNoHSArray=[responseletetudedict valueForKey:@"Phoneno"];
FaxnoHSArray=[[NSMutableArray alloc] init];
FaxnoHSArray=[responseletetudedict valueForKey:@"Faxno"];
LatitudeHSArray=[[NSMutableArray alloc] init];
LatitudeHSArray=[responseletetudedict valueForKey:@"Latitude"];
LongitudeHSArray=[[NSMutableArray alloc] init];
LongitudeHSArray=[responseletetudedict valueForKey:@"Longitude"];
TypeHSArray=[[NSMutableArray alloc] init];
TypeHSArray=[responseletetudedict valueForKey:@"Type"];
for (int i=0; i<NameHSArray.count; i++) {
double LatitudeDouble = [LatitudeHSArray[i] doubleValue];
double LongitudeDouble = [LongitudeHSArray[i] doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(LatitudeDouble, LongitudeDouble);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = NameHSArray[i];
marker.snippet=AddressHSArray[i];
userData = [[NSArray alloc] initWithObjects:NameHSArray[i], AddressHSArray[i],FacilitiesHSArray[i], PhoneNoHSArray[i],FaxnoHSArray[i], TypeHSArray[i], nil];
marker.userData = userData;
if([TypeHSArray[i] isEqualToString:@"ESIC"])
{
marker.icon = [UIImage imageNamed:@"mapicon2.png"];
}
else
{
marker.icon = [UIImage imageNamed:@"mapicon1.png"];
}
GMSCameraUpdate *zoomCamera = [GMSCameraUpdate zoomIn];
[mapView animateWithCameraUpdate:zoomCamera];
marker.map = mapView;
}
当我点击诺贝尔医院时加入图片我给代表打电话
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
// your click action
StringAddress = marker.snippet;
StringName = marker.title;
NSLog(@"Address=%@",StringAddress);
NSLog(@"Name= %@",StringName);
lblNamepopup.text=StringName;
lblAddresspopup.text=StringAddress;
NSLog(@"User Data Array = %@",userData);
viewpopup.hidden=NO;
viewpopup.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
viewpopup.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
}
在这个委托中听到我需要获取字符串地址的当前名称。但是听到我收到Last值意味着字符串得到覆盖。如何获取从数组中单击的值。在此先感谢!
答案 0 :(得分:1)
您可以获得索引
Try below query :
SELECT MONTH(f.Created_Date), f.Created_By_User_ID
FROM Fees f
WHERE EXISTS(SELECT 1 FROM [User] u WHERE f.Created_By_User_ID= u.User_ID
AND DATEDIFF(DAY,f.Created_Date,'2016-01-01') <= 0 AND
DATEDIFF(DAY,f.Created_Date,'2016-12-31') >= 0
---编辑---
您也可以使用
注意: -
您可以通过代码段传递数据,但将代码段显示数据传递到信息窗口。这样您就可以创建自定义信息窗口并根据需要显示数据。
像这样,
-(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
{
NSInteger index = [NameHSArray indexOfObject:marker.title];
NSLog(@"%ld",(long)index);
}
retrive
像这样,
NSArray * userData = [NSArray alloc] initWithObjects:FacilitiesHSArray[i], PhoneNoHSArray[i],FaxnoHSArray[i], nil];
NSString *userDataString = [userData componentsJoinedByString:@";"];
marker.snippet = userDataString;
你可以这样做
NSString *userDataString = marker.snippet;
NSArray *array = [userDataString componentsSeparatedByString:@";"];
NSLog(@"%@",array);