仍然在这里使用Ojective-C:)
我正在尝试通过触摸按钮重新加载mapView及其所有属性,但它没有填充。这是我正在使用的:
-(IBAction)refreshLocation:(id)sender {
[self refresh];
}
-(void)refresh {
[mapView setNeedsDisplay];
}
没有发生任何事情:这是我如何聚合数据点,可能不是最实用的,但对我的情况来说是最合理的:
MapViewController.h
#import <MapKit/MapKit.h>
#import <MapKit/MKAnnotation.h>
@interface MapViewController : UIViewController
{
IBOutlet MKMapView *mapView;
IBOutlet UISegmentedControl *segmentedControl;
__weak IBOutlet UIBarButtonItem *refreshLocation;
}
@property (nonatomic, retain) MKMapView *mapView;
@property (nonatomic, retain) UISegmentedControl *segmentedControl;
- (IBAction)segmentedControllChanged:(id)sender;
- (IBAction)refreshLocation:(id)sender;
@end
MapViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
double cost2 = [self.latLocation doubleValue];
double cost = [self.longLocation doubleValue];
CLLocationCoordinate2D location;
location.latitude = cost2;
location.longitude = cost;
MKCoordinateRegion region;
region.center.latitude = (double) cost2;
region.center.longitude = (double) cost;
region.span = MKCoordinateSpanMake(.99, .99);
region = [self.mapView regionThatFits:region];
[self.mapView setRegion:region animated:YES];
-(NSString *)latLocation {
NSError *error = nil;
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com"] encoding:NSASCIIStringEncoding error:&error];
if(html) {
NSLog(@"HTML %@", html);
NSRange r = [html rangeOfString:@"<h3 class=\"font\">"];
if (r.location != NSNotFound) {
NSRange r1 = [html rangeOfString:@"</h3>"];
if (r1.location != NSNotFound) {
if (r1.location > r.location) {
NSString *latitude = [html substringWithRange:NSMakeRange(NSMaxRange(r), r1.location - NSMaxRange(r))];
NSLog(@"%@", latitude);
latLocation = latitude;
}
}
}
}
return latLocation;
}
-(NSString *)longLocation {
NSError *error = nil;
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com"] encoding:NSASCIIStringEncoding error:&error];
if(html) {
NSLog(@"HTML %@", html);
NSRange r = [html rangeOfString:@"<h4 class=\"font\">"];
if (r.location != NSNotFound) {
NSRange r1 = [html rangeOfString:@"</h4>"];
if (r1.location != NSNotFound) {
if (r1.location > r.location) {
NSString *longitude = [html substringWithRange:NSMakeRange(NSMaxRange(r), r1.location - NSMaxRange(r))];
NSLog(@"%@", longitude);
longLocation = longitude;
}
}
}
}
return longLocation;
}
-(NSString *)annotationTitle {
NSError *error = nil;
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com"] encoding:NSASCIIStringEncoding error:&error];
if(html) {
NSLog(@"HTML %@", html);
NSRange r = [html rangeOfString:@"<h1 class=\"font\">"];
if (r.location != NSNotFound) {
NSRange r1 = [html rangeOfString:@"</h1>"];
if (r1.location != NSNotFound) {
if (r1.location > r.location) {
NSString *titleString = [html substringWithRange:NSMakeRange(NSMaxRange(r), r1.location - NSMaxRange(r))];
NSLog(@"%@", titleString);
annotationTitle = titleString;
}
}
}
}
return annotationTitle;
}
-(NSString *)subTitle {
NSError *error = nil;
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://mywebsite.com"] encoding:NSASCIIStringEncoding error:&error];
if(html) {
NSLog(@"HTML %@", html);
NSRange r = [html rangeOfString:@"<h2 class=\"font\">"];
if (r.location != NSNotFound) {
NSRange r1 = [html rangeOfString:@"</h2>"];
if (r1.location != NSNotFound) {
if (r1.location > r.location) {
NSString *subtitleString1 = [html substringWithRange:NSMakeRange(NSMaxRange(r), r1.location - NSMaxRange(r))];
NSLog(@"%@", subtitleString1);
subTitle = subtitleString1;
}
}
}
}
return subTitle;
}
- (IBAction)refreshLocation:(id)sender {
[self refresh];
}
-(void)refresh
{
[self.mapView setNeedsDisplay];
// Create the request.
}
我需要重新加载所有这些字符串方法,以从mywebsite.com中获取这些标题中显示的新数据。但目前一切都没有发生。有什么建议吗?
答案 0 :(得分:0)
试试这个
- (IBAction)refreshLocation:(id)sender {
[self viewDidLoad];
}