Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBOutlet Label does not get data

Tags:

ios

uilabel

ios6

Hi I am newbie in StackOverFlow and iOS 6..

It will be so simple for experienced developer..

in .h file..

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

in .m file..

@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];

    }
}

Problem is as follows..

self.wordLabel.text = theSighting.word;

In spite of theSighting.word has data, but self.wordLabel.text does not contain any data...

Absolutely I connected the IBOutlet in storyboard.

What is wrong above?.

Edited. I add some part of source. I hope you are not uncomfortable with this.

//  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.

like image 350
Sugarmine Boy Avatar asked Jun 11 '26 17:06

Sugarmine Boy


1 Answers

I think you are calling -(void)configureView before -(void)viewDidLoad, in which case wordLabel is nil when you are trying to assign anything to it.

Try calling -(void)configureView inside -(void)viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self configureView];
}
like image 79
Daniel Avatar answered Jun 14 '26 08:06

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!