soulshined
soulshined

Reputation: 10602

UILabel method won't return

I keep getting the declaration hides instance variable, but i don't know where to call it. I'm trying to reference it programmatically. I created the UILabel Programmatically so I don't have anything to drag it to in .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];
}

I think i'm just overlooking something simple because its a simple error. please help :)

Upvotes: 0

Views: 83

Answers (1)

Rashad
Rashad

Reputation: 11197

Its easy thing, Look at this:

in your .h you declared

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

And in you -(UILabel *)parseLabel you did this:

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

The variable names are same. Thats why you are getting this error. :)

Upvotes: 1

Related Questions