//通過(guò)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;
}
這是一個(gè)封裝好的方法,直接創(chuàng)建一個(gè)ViewController的對(duì)象就可以調(diào)用該方法。
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
NSLog(@"subview==%@",subView);
}
}
用該方法遍歷UIView上的所有控件,就可以獲得某種控件潦蝇,再配合tag可以取到某一個(gè)具體的控件款熬。
UINavigationController *parentViewController = (UINavigationController*)self.navigationController.parentViewController ;
NSLog(@"parentViewController==%@",parentViewController);
這個(gè)方法可以獲取父類的ViewCOntroller
通過(guò)經(jīng)緯度計(jì)算距離
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;