UILabel方法不会返回

时间:2014-09-17 04:22:03

标签: ios variables methods uilabel

我一直收到声明隐藏实例变量,但我不知道在哪里调用它。我试图以编程方式引用它。我以编程方式创建了UILabel所以我没有任何东西可以将它拖到.xib中

MapViewController.h

#import <UIKit/UIKit.h>
#import "RESideMenu.h"
#import <MapKit/MapKit.h>

@interface MapViewController : UIViewController
{
IBOutlet MKMapView *mapView;
IBOutlet UISegmentedControl *segmentedControl;
IBOutlet UILabel *parseLabel;
}


@property (nonatomic, retain) MKMapView *mapView;
@property (nonatomic, retain) UISegmentedControl *segmentedControl;
@property (nonatomic, retain) IBOutlet UILabel *parseLabel;

- (IBAction)segmentedControllChanged:(id)sender;

@end

MapViewController.m

#import "MapViewController.h"
#import "MapViewAnnotation.h"
#import "Config.h"

@interface MapViewController ()

@end

@implementation MapViewController
@synthesize mapView, segmentedControl, parseLabel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization

}
return self;
}

-(UILabel *)parseLabel {
UILabel *parseLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, 1, 200, 40)];
NSError *error = nil;
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://harryhippie.com/app-currentlocationparse"] 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 *subtitleString = [html substringWithRange:NSMakeRange(NSMaxRange(r), r1.location - NSMaxRange(r))];
                NSLog(@"%@", subtitleString);
                self.parseLabel.text = subtitleString;
}
        }
    }
}
return parseLabel;
}

- (void)viewDidLoad
{
[self.navigationController.navigationBar addSubview:parseLabel];
[super viewDidLoad];
}

我认为我只是忽略了一些简单的错误,因为它只是一个简单的错误。请帮助:)

1 个答案:

答案 0 :(得分:1)

这很简单,看看这个:

在你宣布的.h中

@property (nonatomic, retain) IBOutlet UILabel *parseLabel;

在你-(UILabel *)parseLabel中你做到了这一点:

UILabel *parseLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, 1, 200, 40)];

变量名称相同。这就是为什么你得到这个错误。 :)