嗨,我是 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 不包含任何数据...
当然,我在故事板中连接了 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
有机发光二极管。