Ios Objective C-在视图控制器的UIView子类上设置标签属性
在我的应用程序中,我在Nib文件中设计了一个自定义谷歌地图pin标记。pin标记的一部分将显示估计到达时间 下面是我加载Nib并尝试设置自定义时间的方式:Ios Objective C-在视图控制器的UIView子类上设置标签属性,ios,objective-c,uiview,Ios,Objective C,Uiview,在我的应用程序中,我在Nib文件中设计了一个自定义谷歌地图pin标记。pin标记的一部分将显示估计到达时间 下面是我加载Nib并尝试设置自定义时间的方式: self.markerPinFromNib = [[[NSBundle mainBundle] loadNibNamed:@"PinWithTimeView" owner:self options:nil] firstObject]; self.markerPinFromNib.estTime.text = @"20"; 运行此操作时,我得
self.markerPinFromNib = [[[NSBundle mainBundle] loadNibNamed:@"PinWithTimeView" owner:self options:nil] firstObject];
self.markerPinFromNib.estTime.text = @"20";
运行此操作时,我得到一个错误:
-[UIView estTime]: unrecognized selector sent to instance
PinWithTimeView.h
#import <UIKit/UIKit.h>
@interface PinWithTimeView : UIView
@property (nonatomic, weak) IBOutlet UIImageView *rotateCircle;
@property (nonatomic, strong) IBOutlet UILabel *estTime;
@end
@interface PinWithTimeView : UIView
@property (nonatomic, weak) IBOutlet UIImageView *rotateCircle;
@property (nonatomic, weak) IBOutlet UILabel *estTime;
-(id)initWithEstTime:(NSString*)time;
@end
#导入
@接口PinWithTimeView:UIView
@属性(非原子,弱)IBUIImageView*旋转圆;
@属性(非原子,强)IBUILabel*estTime;
@结束
有人能指出我做错了什么吗?您应该将实例从nib转换为有效的
PinWithTimeView
。像这样:
((PinWithTimeView *)self.markerPinFromNib).estTime.text = @"20";
因为
loadNibNamed:owner:options:
将返回一个数组includeUIView
实例。您应该将实例从nib转换为有效的PinWithTimeView
。像这样:
((PinWithTimeView *)self.markerPinFromNib).estTime.text = @"20";
因为
loadNibNamed:owner:options:
将返回一个数组includeUIView
实例。在您的PinWithTimeView.h中
#import <UIKit/UIKit.h>
@interface PinWithTimeView : UIView
@property (nonatomic, weak) IBOutlet UIImageView *rotateCircle;
@property (nonatomic, strong) IBOutlet UILabel *estTime;
@end
@interface PinWithTimeView : UIView
@property (nonatomic, weak) IBOutlet UIImageView *rotateCircle;
@property (nonatomic, weak) IBOutlet UILabel *estTime;
-(id)initWithEstTime:(NSString*)time;
@end
在您的PinWithTimeView.m中
-(id)initWithEstTime:(NSString*)time{
self = [super init];
if (self) {
self = [[[NSBundle mainBundle] loadNibNamed:@"PinWithTimeView" owner:self options:nil] objectAtIndex:0];
self.estTime.text = time;
}
return self;
}
在控制器中
self.markerPinFromNib = [[PinWithTimeView alloc]initWithEstTime:@"20"];
在您的PinWithTimeView.h中
#import <UIKit/UIKit.h>
@interface PinWithTimeView : UIView
@property (nonatomic, weak) IBOutlet UIImageView *rotateCircle;
@property (nonatomic, strong) IBOutlet UILabel *estTime;
@end
@interface PinWithTimeView : UIView
@property (nonatomic, weak) IBOutlet UIImageView *rotateCircle;
@property (nonatomic, weak) IBOutlet UILabel *estTime;
-(id)initWithEstTime:(NSString*)time;
@end
在您的PinWithTimeView.m中
-(id)initWithEstTime:(NSString*)time{
self = [super init];
if (self) {
self = [[[NSBundle mainBundle] loadNibNamed:@"PinWithTimeView" owner:self options:nil] objectAtIndex:0];
self.estTime.text = time;
}
return self;
}
在控制器中
self.markerPinFromNib = [[PinWithTimeView alloc]initWithEstTime:@"20"];
仍在获取“[UIView estTime]:发送到实例的无法识别的选择器”。。。知道为什么吗?你能分享一下代码崩溃的那一行吗。请使用断点进行调试,仍将获取“[UIView estTime]:发送到实例的无法识别的选择器”。。。知道为什么吗?你能分享一下代码崩溃的那一行吗。请使用断点进行调试