我removeAnnotations用来删除我的注释,mapView但同样删除用户位置ann.我该如何防止这种情况,或者如何让用户回来查看?
NSArray *annotationsOnMap = mapView.annotations;
[mapView removeAnnotations:annotationsOnMap];
Run Code Online (Sandbox Code Playgroud) 我有一个用户位置(蓝点)和注释mapView.选择注释时,我将文本设置为distLabel- "距离点%4.0f m.".用户移动时如何更新该文本标签?
didSelectAnnotationView:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
CLLocation *pinLocation =
[[CLLocation alloc] initWithLatitude:
[(MyAnnotation*)[view annotation] coordinate].latitude
longitude:
[(MyAnnotation*)[view annotation] coordinate].longitude];
CLLocation *userLocation =
[[CLLocation alloc] initWithLatitude:
self.mapView.userLocation.coordinate.latitude
longitude:
self.mapView.userLocation.coordinate.longitude];
CLLocationDistance distance = [pinLocation distanceFromLocation:userLocation];
[distLabel setText: [NSString stringWithFormat:@"Distance to point %4.0f m.",
distance]];
}
Run Code Online (Sandbox Code Playgroud)
我知道有一个功能didUpdateToLocation,但我怎么能用didSelectAnnotationView呢?
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//Did update to location
}
Run Code Online (Sandbox Code Playgroud) 我曾经为我inputView展示uipickerview过textfield,但我也用它来做textfield其他功能.我如何能显示标准键盘我用后inputView为textfield?
textfield.inputView = pickrView;
Run Code Online (Sandbox Code Playgroud) 我使用此方法显示带小数分隔符的键盘
myTextField.keyboardType=UIKeyboardTypeDecimalPad;
Run Code Online (Sandbox Code Playgroud)
如何将逗号更改为点分隔符?
我有一个芬兰语区域.使用逗号,小数不适用于我的应用程序.
-(IBAction)calculate {
float x = ([paino.text floatValue]) / ([pituus.text floatValue]) *10000;
label.text = [[NSString alloc] initWithFormat:@"%0.02f", x];
}
Run Code Online (Sandbox Code Playgroud) 在我的viewDidLoad我设置
UISwipeGestureRecognizer *swipeRecognizerU = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpDetected:)]; swipeRecognizerU.direction = UISwipeGestureRecognizerDirectionUp; [self.view addGestureRecognizer:swipeRecognizerU];
Run Code Online (Sandbox Code Playgroud)
当我通过弹出窗口加载新视图时,我需要禁用该手势
// show popup view
-(IBAction)showPopup:(id)sender
{
MJDetailViewController *detailViewController = [[MJDetailViewController alloc] initWithNibName:@"MJDetailViewController" bundle:nil];
[self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationSlideBottomBottom];
}
Run Code Online (Sandbox Code Playgroud)
在弹出视图被解除后,我需要设置滑动手势.
// hide popup view
-(IBAction)hidePopup:(id)sender
{
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationSlideBottomBottom];
}
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
我有开关,我想检测是否有任何开关被改变位置,如果有变化我需要开始我的行动.
开关存储位置 NSUserDefaults
- (IBAction)saveSwitch:(id)sender
{
NSUserDefaults *defs1 = [NSUserDefaults standardUserDefaults];
[defs1 setBool: blackSwitch.on forKey: @"blackKey"];
NSUserDefaults *defs2 = [NSUserDefaults standardUserDefaults];
[defs2 setBool: greenSwitch.on forKey: @"greenKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
Run Code Online (Sandbox Code Playgroud) 现在,当我选择注释时,我将视图重新定位为居中,如下所示:
[mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
Run Code Online (Sandbox Code Playgroud)
但是,如何才能将视图重新定位到垂直而不是水平居中?
我的数据结构是:

现在我遍历列表并添加" Name "字符串NSMutableArray,然后使用搜索和过滤数据NSPredicate.
我如何搜索整个列表?通过所有数组中的Name和Address字符串?
过滤数据:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
searchResults = [sectionsNames filteredArrayUsingPredicate:resultPredicate];
}
Run Code Online (Sandbox Code Playgroud)
加载数据中:
#pragma mark -
#pragma mark Load plist file
- (void)loadPList
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [[documentPaths lastObject] stringByAppendingPathComponent:@"data.plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
NSMutableDictionary *resultDic = [[NSMutableDictionary alloc] init];
NSMutableArray *resultArray = [[NSMutableArray alloc] init];
NSMutableArray *resultName = [[NSMutableArray alloc] …Run Code Online (Sandbox Code Playgroud) 我使用过滤表格结果 NSPredicate
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"Name CONTAINS[cd] %@ OR Address CONTAINS[cd] %@",
searchText,
searchText];
searchResults = [NSMutableArray array];
for (key in dict) {
if ([resultArray containsObject:key]) {
NSArray *array = [dict objectForKey:key];
matches = [array filteredArrayUsingPredicate:resultPredicate];
if (matches.count > 0) {
[searchResults addObjectsFromArray:matches];
// sorting array
NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"Distance" ascending:YES];
[searchResults sortUsingDescriptors:[NSArray arrayWithObject:sort]];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用排序结果数组 NSSortDescriptor
NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"Distance" ascending:YES];
[searchResults sortUsingDescriptors:[NSArray arrayWithObject:sort]];
Run Code Online (Sandbox Code Playgroud)
它有效,但不是所有结果:

可能重复:
如何在Xcode中用+替换空格
在这个字符串中我需要替换空格:
controller.body = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%@,%@", pinTitle.text, newlatLabel.text, newlogLabel.text];
Run Code Online (Sandbox Code Playgroud) ios ×9
xcode ×6
annotations ×2
mkmapview ×2
nspredicate ×2
center ×1
decimal ×1
distance ×1
filter ×1
gesture ×1
inputview ×1
iphone ×1
mkannotation ×1
replace ×1
search ×1
space ×1
string ×1
swipe ×1
uipickerview ×1
uitextfield ×1
userlocation ×1