Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Objective C-在视图控制器的UIView子类上设置标签属性_Ios_Objective C_Uiview - Fatal编程技术网

Ios Objective C-在视图控制器的UIView子类上设置标签属性

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"; 运行此操作时,我得

在我的应用程序中,我在Nib文件中设计了一个自定义谷歌地图pin标记。pin标记的一部分将显示估计到达时间

下面是我加载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
@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:
将返回一个数组include
UIView
实例。

您应该将实例从nib转换为有效的
PinWithTimeView
。像这样:

((PinWithTimeView *)self.markerPinFromNib).estTime.text = @"20";

因为
loadNibNamed:owner:options:
将返回一个数组include
UIView
实例。

在您的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]:发送到实例的无法识别的选择器”。。。知道为什么吗?你能分享一下代码崩溃的那一行吗。请使用断点进行调试