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

  • SEARCH
  • Home
  • 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 906601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:24:51+00:00 2026-05-15T16:24:51+00:00

I am new to objective C and I have a c++ background. I want

  • 0

I am new to objective C and I have a c++ background. I want to display a value in the label on the screen. I am calling the label value from the MainView.m. However, the label becomes blank after I click a button instead of printing a value. What is the problem? Here is the code.

MainView.h

@interface MainView : UIView {
int a;
}

-(int) vr;

@end

MainView.m

-(int) vr
{
return 100;
}

@end

MainViewController.h

@interface MainViewController : UIViewController {

IBOutlet UILabel *myLabel;

NSMutableString *displayString;

MainView *view1;
}

@property (nonatomic, retain) UILabel *myLabel;

@property (nonatomic, retain) NSMutableString *displayString;

  • (IBAction)showInfo;

  • (IBAction) pressButton:(id) sender;

@end

MainViewController.m

@synthesize myLabel, displayString;

-(IBAction) pressButton:(id) sender{

[displayString appendFormat:@"%i", view1.vr];
myLabel.text = displayString;}



 - (void)viewDidLoad {
 view1 = [[MainView alloc] init];
 [super viewDidLoad];}

- (void)dealloc {
[view1 dealloc];
[super dealloc];}

I have not mentioned code that had been auto generated. This is enough to get the whole picture. I tried a lot to debug this thing. I believe that IBAction carries out direct command such that

myLabel.text = @”string”;

but it does not invoke any method or class. Any subtle ideas? Thanks.

  • 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-05-15T16:24:52+00:00Added an answer on May 15, 2026 at 4:24 pm

    Few issues:

    1
    In MainView.h you declare -(id) vr;
    And in MainView.m it returns int.

    2
    Maybe pressButton is not connected to the right event in Interface Builder (it is usually touch up inside).
    Try to write to log in this method.

    3
    Maybe myLabel is not connected to the label in the Interface Builder.
    Try to set tome hard-coded string to label’s text property.

    4
    Do you initiate view1 in some place?
    Can you post this piece of code too?

    5
    You can use [displayString appendFormat:@"%i", view1.vr];…

    EDIT (due to changes in question):

    6
    The line [super viewDidLoad]; should be the first line inside viewDidLoad.

    7
    [view1 dealloc]; – never call dealloc directly on objects. Call release instead. The only place, where you can and should use dealloc is the line [super dealloc]; inside dealloc method.

    8
    When you format your question/answer in Stack Overflow, remember that each code line should start with at least 4 spaces (or tab). Try reformatting you question by adding 4 spaces in the beginning of each code line.

    9
    I think that displayString is not initiated. Add the next line in the viewDidLoad: displayString = [NSMutableString new];

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

Sidebar

Related Questions

I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background
New to Objective-C, and i am basically from c++ background. I am learning now
hi i am new to java....moved from objective c (iphone background) all we know
I'm new to HTML; however I have programming experience with Objective-C, here's my code:
I am new to Objective-C and I have no clue why this code is
I am new to Objective-C and iPhone I have to sort a NSDictionary using
I'm new in objective-C and i wonder if its correct: I have a class
I am new to objective-c. I have the following: @interface HPSEnumerations : NSObject typedef
I am relatively new to Objective-C / iPhone programming, and have only created single
I'm new to objective C and currently working on a small project. I have

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.