当循环遍历DOM时,我如何检查是否到达了body元素?(when looping through the DOM how do I check if I reached the body element?)
我正在通过DOM将链接元素循环到具有类.ui-mobile-viewport的最近元素。 这可以是DIV或BODY元素。
我需要检查它是哪个元素并且无处可寻......这就是我正在尝试的:
var targetViewport;
//循环将targetViewport设置为$('div.ui-mobile-viewport')或$('body.ui-mobile-viewport')
if ( targetViewport === $('body') ) { console.log("found a body"); }
感谢帮助!
I'm looping through the DOM from a link element to the closest element with class .ui-mobile-viewport. This can either be a DIV or the BODY element.
I need to check which element it is and am getting nowhere... this is what I'm trying:
var targetViewport;
// loop sets targetViewport as a $('div.ui-mobile-viewport') or $('body.ui-mobile-viewport')
if ( targetViewport === $('body') ) { console.log("found a body"); }
Thanks for help!
原文:https://stackoverflow.com/questions/10316839
最满意答案
您可以在执行segue或推送新控制器时将
annotation
或lat long
传递给另一个视图控制器。 如果您正在使用segue,那么您可以使用prepare for segue
方法。第二件事你可以为mapview制作一个
custom class
。 并且可以在其中放置一些属性,如注释或lat long,然后创建此类的对象并设置此属性,以便根据该属性返回地图视图(相应的make方法)。 您可以在许多viewcontroller中使用类,而不仅仅是两个。根据评论更新:
请参阅此链接以了解如何推送新的视图控制器。 并参考这个故事板segue教程 。 实际上它是概念,并且不可能在这里解释一切如果你在代码中有一些错误然后我可以在这里解决但是为了学习整个概念你应该遵循不同的教程和笔记。 做研究。 谷歌你会发现很多链接。
希望这会有所帮助:)
you can pass
annotation
orlat long
to another view controller while performing segue or push new controller. If you are using segue then you can useprepare for segue
method.Second thing you can make a
custom class
for mapview. and can put some properties in it like annotation or lat long then create object of this class and set this property so according that properties this class return map view (make method accordingly). you can use class in many viewcontroller not only in just two.Update as per comment :
refer this link to know how to push new view controller. and refer this storyboard segue tutorial. Actually it concepts and not possible to explain here everything if you have some error in code then i can solve here but for learn whole concepts you should follows different tutorials and notes. do research. google it you will find many links.
hope this will help :)
相关问答
更多-
如果你想从另一个打开ViewController ,那么你应该在你的IBAction这样定义它。 尽管将viewController为属性是个好主意。 FirstViewController.h @class SecondViewController; @interface FirstViewController : UIViewController @property(strong,nonatomic)SecondViewController *secondViewController; @end ...
-
如何从一个View Controller导航到另一个使用Swift(How to Navigate from one View Controller to another using Swift)[2023-07-07]
为第二个视图控制器创建一个swift文件(SecondViewController.swift),并在适当的函数类型中创建: let secondViewController = self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController self.navigationController.pushViewController(secondViewControl ... -
使用iPhone应用程序中的Map View读取当前位置(Read current location using Map View in iPhone applications)[2022-07-11]
如果你有一个名为mapView的MKMapView对象,你可以: mapView.showsUserLocation = YES; 这将打开MKMapView的内置定位服务。 您不需要必须处理CLLocation Manager,因为MKMapView将处理为您定位设备的工作。 现在,如果您之前从未与代表合作过,那么接收MKMapView生成的更新会更加棘手。 在.h中,您希望采用协议。 然后,紧接着上面一行,说: mapView.delegate = self; ... -
按照Paulw11的说法,我发现了使用Notifications的更快的解决方案。 从第一个视图Controller内的LocationManager委托方法发送通知: class MapViewController: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { ...
-
您可以在执行segue或推送新控制器时将annotation或lat long传递给另一个视图控制器。 如果您正在使用segue,那么您可以使用prepare for segue方法。 第二件事你可以为mapview制作一个custom class 。 并且可以在其中放置一些属性,如注释或lat long,然后创建此类的对象并设置此属性,以便根据该属性返回地图视图(相应的make方法)。 您可以在许多viewcontroller中使用类,而不仅仅是两个。 根据评论更新: 请参阅此链接以了解如何推送新的视图控 ...
-
您可以使用UITapGestureRecognizer let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tapHandler(_:))) mapView.addGestureRecognizer(gestureRecognizer) @objc func tapHandler(_ gestureReconizer: UIGestureRecognizer) { ...
-
您需要计算出您想要查看地图的区域,然后使用[mapView setRegion:newRegion animated:YES] ref 。 MKCoordinateRegion由您已经创建的CLLocationCoordinate2D和MKCoordinateSpan组成 。 这是一个跨度的例子 MKCoordinateSpan span; span.latitudeDelta = 1.5; span.longitudeDelta = 1.0; MKCoordinateRegion newRegion; n ...
-
通过单击下面的按钮调用方法。 - (void)gotoLocation { float spanX = 0.05; float spanY = 0.05; MKCoordinateRegion region; region.center.latitude = mapView.userLocation.coordinate.latitude; region.center.longitude = mapView.user ...
-
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if ([CLLocationManager significantLocationChangeMonitoringAvailable]) { if (OUTPUT_LOGS) NSLog(@"Stopped monitoring for significant changes"); [[self locationM ...
-
你可以使用locationM.stopUpdatingLocation() 开始更新位置 override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) locationM.startUpdatingLocation() } 并停止 override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear( ...