Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-30-2009, 03:22 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 48
Question Passing NSInteger from View to Subview?

I am not sure why this is not working.

I am simply trying to pass a NSInteger from a view to its subView and NSLog is showing that the value is not making it. Although other variables (such as NSString work).

Here is my code:

SomeViewController.h
Code:
#import <UIKit/UIKit.h>
#import "TimedBarView.h"

@interface SomeViewController : UIViewController
{

	IBOutlet TimedBarView				*timedBarSubView;
	
}

@property (nonatomic,retain) IBOutlet TimedBarView *timedBarSubView;
SomeViewController.m
Code:
@synthesize timedBarSubView;

...

- (void)viewDidLoad
{
    [super viewDidLoad];
    if(timedBarSubView == nil)
	{
		TimedBarView	*subViewController =
		[[TimedBarView alloc] initWithNibName:@"TimedBarView" bundle:[NSBundle mainBundle]];
		
		[self setTimedBarSubView:subViewController];

		[subViewController release];
	}

	timedBarSubView.view.backgroundColor = [UIColor clearColor];
	[timedBarSubView upGrade];
	timedBarSubView.itemName.text = @"Town Villa";

	timedBarSubView.levelNum = 5;	
	
	CGRect r = [timedBarSubView.view frame];
	r.origin.x = 0.0f;
	r.origin.y = 290.0f;
	[timedBarSubView.view setFrame:r];
	[self.view addSubview:timedBarSubView.view];
}

...
TimedBarView.h
Code:
@interface TimedBarView : UIViewController
{

...

	NSInteger levelNum;

...

}

@property (nonatomic) NSInteger levelNum;
TimedBarView.m
Code:
@synthesize levelNum;

...

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"The current value of levelNum is %d", levelNum);
}
But I always get this in the console:

The current value of levelNum is 0

even when I am sending in a constant 5.

Any ideas what's wrong here?
encryption is offline   Reply With Quote
Old 10-30-2009, 06:38 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 48
Default Solution found

Setting the NSinteger value was causing viewDidLoad function to run prior to setting the value for some reason.

Anyways, I changed my code to use a method rather than setting a variable and it's working now.

Thanks!
encryption is offline   Reply With Quote
Reply

Bookmarks

Tags
nsinteger, passing variables, subview, view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:14 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0