gpt4 book ai didi

ios - IBOutlet Label 获取不到数据

转载 作者:行者123 更新时间:2023-12-01 00:32:26 25 4
gpt4 key购买 nike

您好,我是 StackOverFlow 和 iOS 6 的新手。

对于有经验的开发人员来说,这将是如此简单..

在.h文件中..

@interface NotKnownDetailView : UITableViewController
@property (weak, nonatomic) IBOutlet UILabel *wordLabel;
@end

在 .m 文件中..

@interface NotKnownDetailView ()
- (void)configureView;
@end

@implementation NotKnownDetailView
@synthesize wordLabel = _wordLabel ;

- (void)configureView{

wordData *theSighting = self.word_data;

if (theSighting) {

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Hello World!"
message:theSighting.verbal
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];

self.wordLabel.text = theSighting.word;

UIAlertView *message2 = [[UIAlertView alloc] initWithTitle:@"Hello World!"
message: self.verbalLabel.text
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message2 show];

}
}

问题如下..

self.wordLabel.text = theSighting.word;

尽管theSighting.word有数据,但是self.wordLabel.text不包含任何数据...

当然,我在 Storyboard中连接了 IBOutlet。

上面有什么问题?

已编辑。我添加了源代码的一部分。我希望你不会对此感到不舒服。

//  NotKnownDetailView.h
#import <UIKit/UIKit.h>

@class wordData ;

@interface NotKnownDetailView : UITableViewController
@property (strong, nonatomic) wordData *word_data;
@property (weak, nonatomic) IBOutlet UILabel *wordLabel;
@property (weak, nonatomic) IBOutlet UILabel *meanLabel;
@property (weak, nonatomic) IBOutlet UILabel *verbalLabel;
@end


// NotKnownDetailView.m

#import "NotKnownDetailView.h"
#import "wordData.h"

@interface NotKnownDetailView ()
//@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation NotKnownDetailView
@synthesize word_data = _word_data, wordLabel = _wordLabel, meanLabel = _meanLabel, verbalLabel = _verbalLabel;

// it is getter setter..
- (void)setWord_data:(wordData *) newWord
{
if (_word_data != newWord) {
_word_data = newWord;
[self configureView];
}
}
- (void)configureView
{

wordData *theSighting = self.word_data;

if (theSighting) {
NSLog(@" Word : %@" ,theSighting.word);

self.wordLabel.text = theSighting.word;
self.meanLabel.text = theSighting.mean;
self.verbalLabel.text = theSighting.verbal;

}
}
- (void)viewDidUnload
{
self.word_data = nil;
[super viewDidUnload];
}

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

@end







// wordData.h

#import <Foundation/Foundation.h>

@interface wordData : NSObject

@property (nonatomic, copy) NSString *word;
@property (nonatomic, copy) NSString *mean;
@property (nonatomic, copy) NSString *verbal;
-(id)initWithName:(NSString *)word meaning:(NSString *)mean verbaling:(NSString *)verbal;
@end


// wordData.m

#import "wordData.h"

@implementation wordData
@synthesize word = _word, mean = _mean , verbal = _verbal ;

-(id)initWithName:(NSString *)word meaning:(NSString *)mean verbaling:(NSString *)verbal{
{
self = [super init];
if (self) {
_word= word;
_mean = mean;
_verbal = verbal ;
return self;
}
return nil;
}

}
@end

SOLED。

最佳答案

我认为你在 -(void)viewDidLoad 之前调用了 -(void)configureView,在这种情况下 wordLabelnil 当您尝试为其分配任何内容时。

尝试在 -(void)viewDidLoad 中调用 -(void)configureView

- (void)viewDidLoad
{
[super viewDidLoad];

[self configureView];
}

关于ios - IBOutlet Label 获取不到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12801646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com