Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:54:03+00:00 2026-06-05T23:54:03+00:00

HomeViewController.h #import DataParser.h @interface HomeViewController : UIViewController <DataParserDelegate> { UILabel *theLabel; } HomeViewController.m #import

  • 0

HomeViewController.h

#import "DataParser.h"
@interface HomeViewController : UIViewController <DataParserDelegate>
{
    UILabel *theLabel;
}

HomeViewController.m

#import "HomeViewController.h"
@implementation HomeViewController
-(void)viewDidLoad
{
    theLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 100, 30)];
    theLabel.text = @"Bob";
    theLabel.font = [UIFont italicSystemFontOfSize:20.0];
    theLabel.textColor = [UIColor whiteColor];
    theLabel.backgroundColor = [UIColor blueColor];
    [self.view addSubview:theLabel];

    UIButton *theButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [theButton addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
    [theButton setTitle:@"Big Button" forState:UIControlStateNormal];
    theButton.frame = CGRectMake(100,100,200,50);
    [self.view addSubview:theButton];
}
-(void)clicked:(id)sender
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0),
    ^{
        DataParser *data = [[DataParser alloc] init];
        data.delegate = self;
        [data loadSomething];

        dispatch_async(dispatch_get_main_queue(),
        ^{
            NSLog(@"Thread done");
        });
    });
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    theLabel.frame = CGRectMake(250,250,100,30);
    theLabel.text = @"This message displays fine";
}
-(void)loadMessage:(NSString *)message
{
    NSLog(@"Received message: %@", message);
    theLabel.frame = CGRectMake(300,300,100,30);
    theLabel.text = @"This message won't display";
}
@end

DataParser.h

@protocol DataParserDelegate;

@interface DataParser : NSObject
@property (weak, nonatomic) id <DataParserDelegate> delegate;
-(void)loadSomething;
@end

@protocol DataParserDelegate <NSObject>
-(void)loadMessage:(NSString *)message;
@end

DataParser.m

#import "DataParser.h"
@implementation DataParser
@synthesize delegate=_delegate;
-(void)loadSomething
{
    [[self delegate] loadMessage:@"ASDF"];
}
@end

-=-=-=-=-=-=-=-=-=-=-=-=-=-

Basically, I create a label and add it to the screen. At this point you can clearly see a Blue button with white text saying “Bob” on it. When you rotate the screen, the button changes text and position just fine. However, if I click the button, it creates a dataParser object, sets the delegate to self, and calls “loadSomething”. Within the dataParser object, “loadSomething” merely calls the delegate method “loadMessage”.

The question is, when “loadMessage” gets called, the NSLog statement prints correctly (“Received message: ASDF”), however, theLabel doesn’t move and doesn’t change its text. Why is this? And how do I fix this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:54:05+00:00Added an answer on June 5, 2026 at 11:54 pm

    Try this code :

    -(void)loadMessage:(NSString *)message
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"Received message: %@", message);
            theLabel.frame = CGRectMake(300,300,100,30);
            theLabel.text = @"This message displays great!";
        });
    }
    

    It should run it on the main thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UIView *view =[[UIView alloc] initWithFrame:CGRect(0,0,300,70)]; //--(View created) someViewController *someViewControllerObject = [..]; //View Controller Object
I'm currently pushing my main UIViewController from appDelegate with this code: HomeViewController *homeViewController =
I have a view controller initialized like this: HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@HomeViewController
@interface SomeViewController : UIViewController <UITextViewDelegate> @property (retain, nonatomic) IBOutlet UIImageView *imageView; @property (nonatomic, retain)
I have a view controller ( HomeViewController ) and push another view controller (
In my iPhone app I have HomeViewController and ContentViewController. I am saving the values
I just want to confirm that I'm understanding correctly, in Interface Builder the Class
My idea is very similar to declare a variable of an interface type in
I am working with a navigation application. I have a homeViewController with two views(accept,
i am unzipping a file on background thread and i am calling HomeViewController on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.