0

.h file:

@property (strong, nonatomic) IBOutlet UILabel *frequencyDetailLabel;

.m file:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //LOCALIZATION
    ..
    self.frequencyDetailLabel.text = NSLocalizedString(@"Select", nil);
}

Then later in my code I try changing the text:

self.frequencyDetailLabel.text = NSLocalizedString(@"Done", nil);

Things I have done so far:

  • Made sure the IBOutlet connection is working properly.
  • Instead of changing the text, I tried changing the textcolor and it worked.
  • Check if the UILabel was null/nil, it is not.
  • Made sure both were pointing at same UILabel
  • In my localizable.strings, both Keys exists.

Anything else I should try?

Edit:

unwind method

- (IBAction)unwindFromFrequencyViewController:(UIStoryboardSegue *)segue {
if ([segue.sourceViewController isKindOfClass:[FrequencyTableViewController class]]) {

    FrequencyTableViewController *frequencyViewController = segue.sourceViewController;

    // if the user clicked Cancel, we don't want to set a frequency (skips code)
    if (frequencyViewController.frequency) {
        NSLog(@"THIS RAN");
        self.howOften = frequencyViewController.frequency;
        if ([frequencyViewController.frequency intValue] == 1) {
            NSLog(@"THIS RAN1");
            self.frequencyDetailLabel.text = @"Every day";
            return;
        } else {
            NSLog(@"THIS RAN2");
            self.frequencyDetailLabel.text = NSLocalizedString(@"Done", nil);
        }
    }
}

}

Daniyar
  • 2,975
  • 2
  • 26
  • 39
apolo
  • 441
  • 4
  • 18
  • Have you tried setting it to "Done" in the `viewWillAppear` to see if the "Done" really exists? IF it works there for "Select" and does not for "Done" then your problem resides elsewhere. – Putz1103 Jul 31 '14 at 14:43
  • 1
    'Later in my code' Where exactly? – duci9y Jul 31 '14 at 14:45
  • 1
    This probably won't solve your problem, but your `IBOutlet` should most likely be `weak` instead of `strong`. More on that: http://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc – Rinat Khanov Jul 31 '14 at 14:47
  • @Putz1103 putting done in `viewWillAppear` does work. I do not think the problem is in the localizable.strings as I mentioned in question. – apolo Jul 31 '14 at 14:47
  • If it works there and doesn't in the other then you are likely trying to update the text from a background thread. All UI updates need to be in the main thread. – Putz1103 Jul 31 '14 at 14:48
  • @duci9y Later is an unwind method from another controller. I added `NSLog` to make sure the code was running and it did. Tried changing the `textcolor` in the same location and it worked. :( – apolo Jul 31 '14 at 14:48
  • @Putz1103 How would I check on what thread it is being called from? – apolo Jul 31 '14 at 14:50
  • Set a breakpoint, then while at that break point look at the call stack. It will have a method hierarchy as well as what thread that hierarchy is running in. If it's not thread 1 then you have a problem and need to asynchronously call to the main thread to update your UI. – Putz1103 Jul 31 '14 at 14:52
  • @Putz1103 It is running from thread 1 :( – apolo Jul 31 '14 at 14:54
  • Thread 1 is not the main thread. I don't think it's running at thread 1 since you say it's an unwind segue. Thread 0 is the main thread. – duci9y Jul 31 '14 at 14:55
  • @duci9y thanks, I will try and figure out how to call from main thread, have never done that before. – apolo Jul 31 '14 at 15:04
  • No no, if it's an unwind, it's **definitely** in the main thread. Could you post your unwind action please? – duci9y Jul 31 '14 at 15:05
  • @duci9y posted on question since it is too long for comment here. – apolo Jul 31 '14 at 15:10
  • Put log statements logging your label before 'this ran2' and after you set 'Done'. – duci9y Jul 31 '14 at 15:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58435/discussion-between-espitia-and-duci9y). – apolo Jul 31 '14 at 15:14

1 Answers1

1

Found solution in another question: UILabel text not being updated

dispatch_async(dispatch_get_main_queue(), ^{
     [self.someLabel setText:someString];
});
Community
  • 1
  • 1
apolo
  • 441
  • 4
  • 18