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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 01-08-2010, 12:17 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 12
nibby is on a distinguished road
Default Accessing root view from subclass/subview

Hi all

I have this class called ballImage which is an UIImageView. I instantiate it from my main viewcontroller (myFirstGameViewController) like this:

Code:
ballImage *ball = [[ballImage alloc] initWithImage:[UIImage imageNamed:@"Ball.png"]];
ball.center = CGPointMake(100,100);
[ball setUserInteractionEnabled:YES];
[self.view addSubview:ball];
Below is my class where i'd like to animate the ball when it is touched. I can't use self.view since i am now in a subview so how do i access the "main view"? (see the "Error"-line)

Code:
#import "ballImage.h"
#import "myFirstGameViewController.h"

@implementation ballImage

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
	NSArray * imageArray  = [[NSArray alloc] initWithObjects:
		[UIImage imageNamed:@"Ball.png"],
		[UIImage imageNamed:@"Ball2.png"],
		[UIImage imageNamed:@"Ball3.png"],
		nil];
	UIImageView * jump = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 116, 116)];
	jump.animationImages = imageArray;
	jump.animationDuration = 1.1;
	jump.contentMode = UIViewContentModeBottomLeft;
	[self.myFirstGameViewController.view addSubview:jump]; // <--Error!
	[jump startAnimating];
}
BTW i don't want to move or shrink the ball i want it to puncture so i have made a few images to do this.

Thanks in advance.
nibby is offline   Reply With Quote
Old 01-08-2010, 07:20 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 271
rarindeed is on a distinguished road
Default

Try the superview property
__________________
@rarindeed


Burstly is the only open and free ad management platform for iPhone app developers.
rarindeed is offline   Reply With Quote
Old 01-09-2010, 05:22 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 12
nibby is on a distinguished road
Default Works

Quote:
Originally Posted by rarindeed View Post
Try the superview property
Thanks a lot - works like a charm
nibby is offline   Reply With Quote
Old 07-03-2011, 03:42 AM   #4 (permalink)
iPhone Newbie
 
Join Date: Dec 2010
Location: Worcestershire, UK
Age: 24
Posts: 66
mwyld is on a distinguished road
Default

Hi, I am trying to do a similar type of thing.

I have an NSObject but can't seem to access the root view controller. Below is where the error is happening.

Code:
UIButton *btnTile = [[UIButton alloc] initWithFrame:CGRectMake(intTempTileX, intTempTileY, intTileWidth, intTileHeight)];
        NSString *strTitle = [NSString stringWithFormat:@"%@", [arrTiles objectAtIndex:i]];
        [btnTile setTitle:strTitle forState:UIControlStateNormal];
        [btnTile addTarget:self action:@selector(dragBegan:withEvent:currentView) forControlEvents: UIControlEventTouchDown];
        [btnTile addTarget:self action:@selector(dragMoved:withEvent:) forControlEvents: UIControlEventTouchDragInside];
        [btnTile addTarget:self action:@selector(dragEnded:withEvent:) forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
        [btnTile setBackgroundColor:[UIColor blueColor]];
        [RootViewController addSubview:btnTile]; <-- This is where the error is happening
        [btnTile release];
mwyld is offline   Reply With Quote
Reply

Bookmarks

Tags
animating, rootviewcontroller, subview

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
» Online Users: 401
7 members and 394 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

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