Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get result from my data class methods when access from ViewController
    primarykey
    data
    text
    <p>I've created a data class name Person with an integer and a bool instance variables. Inside my ViewController "initWithNibName" I initialize </p> <pre><code> anObject = [[Person alloc] init]; </code></pre> <p>Inside the View controller have defined an IBAction. I want to toggle the bool value in person class on each click. I can display text on each click and even append it. But unable to print the int value or bool value from my Data Class.</p> <p>Person.h file</p> <pre><code> @interface Person : NSObject { int pheight; BOOL palive; } -(Person*) init; -(void) setPersonheight: (int) h andAlive: (BOOL) pn; -(int) personHeight; -(void) display; -(BOOL) isPersonAlive; @end </code></pre> <p>Person.m file</p> <pre><code> #import "Person.h" @implementation Person -(Person*) init{ self = [super init]; if (self){ [self setPersonheight:5 andAlive:YES]; } return self; } -(void) setPersonheight: (int) h andAlive: (BOOL) pn{ pheight = h; palive = pn; } -(int) personHeight{ return pheight; } -(void) display{ if(palive){ palive = NO; } else { palive = YES; } } -(BOOL) isPersonAlive{ return YES; } @end </code></pre> <p>*ViewController.h file</p> <pre><code> @interface Demo9ViewController : UIViewController { UILabel *outlet; Person *anObject; //id anObject; } @property (nonatomic, retain) IBOutlet UILabel *outlet; -(IBAction) displayPerson:(id) sender; @end </code></pre> <p>*View controller.m file</p> <pre><code> -(IBAction) displayPerson:(id) sender{ [anObject display]; NSString *myPerson = [NSString stringWithFormat:@"%d",[anObject personHeight]]; NSString *string = [outlet.text stringByAppendingString:myPerson]; outlet.text = string; } </code></pre> <p>Can someone tell, what wrong am I doing here ?</p> <p>Thanks,</p> <p>Regards, M Tahir</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload