当我尝试运行它时,我收到一条错误,上面写着“语义问题:在'UISlider'类型的对象上找不到属性'文本'”
这里有什么问题?
以下是头文件中的代码:
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *nameField;
@property (strong, nonatomic) IBOutlet UITextField *numberField;
@property (strong, nonatomic) IBOutlet UISlider *sliderLabel;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;
- (IBAction)sliderChanged:(id)sender;
@end
实施档案:
#import "BIDViewController.h"
@implementation BIDViewController
@synthesize sliderLabel;
@synthesize nameField;
@synthesize numberField;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setNameField:nil];
[self setNumberField:nil];
[self setSliderLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender
{
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
int progressAsInt = (int)roundf(slider.value);
sliderLabel.text = [NSString stringWithFormat:@"%d",progressAsInt];
}
@end
答案 0 :(得分:3)
我怀疑您的sliderLabel
已被声明为类UISlider
的对象,而它应该是UILabel
。你能在头文件中验证sliderLabel的@property
声明吗?
答案 1 :(得分:0)
我在NSManagedObject上有相同的消息。我的解决方案是将目标的Build Settings的“Search Paths”中的“Always Search User Paths”设置为“No” 希望这也有帮助。