Ios UILabel方法赢得';不归
我一直得到声明隐藏实例变量,但我不知道在哪里调用它。我试图以编程方式引用它。我以编程方式创建了UILabel,因此没有任何东西可以将其拖动到in.xib中 MapViewController.hIos UILabel方法赢得';不归,ios,variables,methods,uilabel,Ios,Variables,Methods,Uilabel,我一直得到声明隐藏实例变量,但我不知道在哪里调用它。我试图以编程方式引用它。我以编程方式创建了UILabel,因此没有任何东西可以将其拖动到in.xib中 MapViewController.h #import <UIKit/UIKit.h> #import "RESideMenu.h" #import <MapKit/MapKit.h> @interface MapViewController : UIViewController { IBOutlet MKMapVi
#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
#导入
#进口“剩余物U.h”
#进口
@接口MapViewController:UIViewController
{
IBMKMAPVIEW*mapView;
IBUI分段控制*分段控制;
IBUILabel*解析标签;
}
@属性(非原子,保留)MKMapView*mapView;
@属性(非原子,保留)UISegmentedControl*segmentedControl;
@属性(非原子,保留)IBUILabel*parseLabel;
-(iAction)SegmentedControlChanged:(id)发送方;
@结束
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];
}
#导入“MapViewController.h”
#导入“MapViewAnnotation.h”
#导入“Config.h”
@接口MapViewController()
@结束
@MapViewController的实现
@综合地图视图、分段控件、parseLabel;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(UILabel*)解析标签{
UILabel*parseLabel=[[UILabel alloc]initWithFrame:CGRectMake(180,1200,40)];
n错误*错误=nil;
NSString*html=[NSString stringWithContentsOfURL:[NSURL URLWithString:@]http://harryhippie.com/app-currentlocationparse“]编码:NSASCIIStringEncoding错误:&错误];
如果(html){
NSLog(@“HTML%@”,HTML);
NSRange r=[html rangeOfString:@”“;
if(r.location!=NSNotFound){
NSRange r1=[html rangeOfString:@”“;
if(r1.location!=NSNotFound){
如果(r1位置>r位置){
NSString*subtitstring=[html substringWithRange:NSMakeRange(NSMaxRange(r),r1.location-NSMaxRange(r));
NSLog(@“%@”,字符串);
self.parseLabel.text=字幕字符串;
}
}
}
}
返回标签;
}
-(无效)viewDidLoad
{
[self.navigationController.navigationBar addSubview:parseLabel];
[超级视图下载];
}
我想我只是忽略了一些简单的事情,因为这是一个简单的错误。请帮助:)这很简单,看看这个: 在您的.h中,您声明
@property (nonatomic, retain) IBOutlet UILabel *parseLabel;
在你的-(UILabel*)parseLabel
中,你做到了:
UILabel *parseLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, 1, 200, 40)];
变量名是相同的。这就是您出现此错误的原因。:) 多谢各位。是的,我删除了那一行。但是现在我如何将从HTML字符串派生的内容输出到导航栏中的UILabel?忽略!我回答了我自己的问题。谢谢你给我指引了正确的方向。我会把这个算作回答,即使它只回答了一半!!谢谢你的帮助:)我在viewDidLoad{self.parseLabel=[[UILabel alloc]initWithFrame…等中做了这件事,谢谢!