嗨,我是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
SOLED。
答案 0 :(得分:2)
我认为您在-(void)configureView
之前致电-(void)viewDidLoad
,在这种情况下wordLabel
是nil
,当您尝试为其分配任何内容时。
尝试在-(void)configureView
-(void)viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
答案 1 :(得分:0)
你能确认theSighting.word是一个NSString值吗?另外我认为如果(theSighting)使用不正确。确保它是一个bool值。尝试使用NSLog(@“%@”theSighting.word);查看是否有任何内容在调试器控制台中打印。