在我的应用程序中,我有一个在 Nib 文件中设计的自定义 Google map 图钉标记。大头针标记的一部分将显示预计到达时间。
这是我加载 Nib 并尝试设置自定义时间的方式:
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
谁能指出我做错了什么?
最佳答案
在你的 PinWithTimeView.h 中
@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;
}
在你的 Controller 中
self.markerPinFromNib = [[PinWithTimeView alloc]initWithEstTime:@"20"];
关于ios - Objective C - 在 View Controller 的 UIView 子类上设置标签属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45261533/