//通过view获取controller
- (UIViewController *)viewController{
for (UIView* next = [self superview]; next; next = next.superview)
{
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController*)nextResponder;
}
}
return nil;
}
这是一个封装好的方法,直接创建一个ViewController的对象就可以调用该方法。
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
NSLog(@"subview==%@",subView);
}
}
用该方法遍历UIView上的所有控件,就可以获得某种控件,再配合tag可以取到某一个具体的控件。
UINavigationController *parentViewController = (UINavigationController*)self.navigationController.parentViewController ;
NSLog(@"parentViewController==%@",parentViewController);
这个方法可以获取父类的ViewCOntroller
通过经纬度计算距离
BOOL JuLi=NO;
CLLocation *orig=[[CLLocation alloc] initWithLatitude:oldlat longitude:oldlong];
CLLocation* dist=[[CLLocation alloc] initWithLatitude:nowlat longitude:nowlong];
CLLocationDistance kilometers=[orig distanceFromLocation:dist];
NSLog(@"距离:%f",kilometers);
if (kilometers>=10)
{
JuLi=YES;
} else{
JuLi=NO;
} return JuLi;