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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-29-2011, 11:33 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: New Zealand
Posts: 49
jvpython is on a distinguished road
Send a message via Skype™ to jvpython
Post Method from parent class

I have a UITableView cell which responds to events like a slider's value changes etc... On certain occasions I need to run a method from the parent class when the user does things with the UITableView cell controls. I cant seem to access methods from my parent class. Is it possible? Thanks
jvpython is offline   Reply With Quote
Old 04-30-2011, 07:25 AM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

A subclass inherits methods from its superclass so this shouldn't be a problem. What method are you talking about?
baja_yu is offline   Reply With Quote
Old 04-30-2011, 03:20 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: New Zealand
Posts: 49
jvpython is on a distinguished road
Send a message via Skype™ to jvpython
Default

Quote:
Originally Posted by baja_yu View Post
A subclass inherits methods from its superclass so this shouldn't be a problem. What method are you talking about?
Any method from the parent class. Lets say I have a method:
Code:
- (void) aMethod {
    //code
}
How would I access it from a subclass?
jvpython is offline   Reply With Quote
Old 04-30-2011, 03:39 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jvpython View Post
Any method from the parent class. Lets say I have a method:
Code:
- (void) aMethod {
    //code
}
How would I access it from a subclass?

You would just call it like this:

Code:
[super aMethod];
The keyword "super" sends a message to the ancestor(s) of the current object. That's what the line

Code:
self = [super init];
that you see in init routines does. It invokes the super-class's init routine.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 04-30-2011, 08:30 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: New Zealand
Posts: 49
jvpython is on a distinguished road
Send a message via Skype™ to jvpython
Default

I tried this but when I build it the compiler says it may not respond to that method and the app crashes. What could be causing this?
jvpython is offline   Reply With Quote
Old 04-30-2011, 09:33 PM   #6 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

We need to see how your class is defined to help you. Can you at least post the beginning of the .h file that shows how you defined the class?
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 04-30-2011, 09:36 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: New Zealand
Posts: 49
jvpython is on a distinguished road
Send a message via Skype™ to jvpython
Default

Quote:
Originally Posted by JasonR View Post
We need to see how your class is defined to help you. Can you at least post the beginning of the .h file that shows how you defined the class?
Sure

Super Class:
Code:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <MediaPlayer/MediaPlayer.h>
#import "SubClass.h"

@interface SuperClass : UIViewController <UIActionSheetDelegate, UITableViewDelegate, UINavigationBarDelegate, UITableViewDataSource, MPMediaPickerControllerDelegate, AVAudioPlayerDelegate> {
//Define stuff
}

SubClass:
Code:
#import <UIKit/UIKit.h>

@interface SubClass : UITableViewCell {
//Define stuff
}
Thanks
jvpython is offline   Reply With Quote
Old 04-30-2011, 11:03 PM   #8 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 31
radio_goober is on a distinguished road
Default

Quote:
Originally Posted by jvpython View Post
Sure

Super Class:
Code:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <MediaPlayer/MediaPlayer.h>
#import "SubClass.h"

@interface SuperClass : UIViewController <UIActionSheetDelegate, UITableViewDelegate, UINavigationBarDelegate, UITableViewDataSource, MPMediaPickerControllerDelegate, AVAudioPlayerDelegate> {
//Define stuff
}

SubClass:
Code:
#import <UIKit/UIKit.h>

@interface SubClass : UITableViewCell {
//Define stuff
}
Thanks
UITableViewCell does not inherit from UIViewController. If you are calling [super whatever] in your UITableViewCell, and trying to access a method of UIViewController, you will throw an error, because those classes are not related.

If you've subclassed UITableViewCell, then it's parent is UITableViewCell. Then it's parent is UIView, then UIResponder, and finally NSObject.

Doctor's orders:
1. Why don't you just tell us specifically what you are trying to do in your UITableViewCell?
2. Google and read up on subclasses and superclasses.
3. Google and read up on class inheritance.
4. Google and read up on object oriented programming. There's actually an active thread in this forum that would explain how to do what you are trying to accomplish. The problem is you don't know enough about programming to know what it is you're actually trying to accomplish.

Last edited by radio_goober; 04-30-2011 at 11:08 PM.
radio_goober is offline   Reply With Quote
Old 04-30-2011, 11:25 PM   #9 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: New Zealand
Posts: 49
jvpython is on a distinguished road
Send a message via Skype™ to jvpython
Default

I only want to do this because in my first class I have a lot of variables which some of my methods use and since I cant access them from the uitableviewcell...
jvpython is offline   Reply With Quote
Old 05-01-2011, 12:02 AM   #10 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

You should be working the other way around. Your UIViewController class should do the work, and call your table cell class, and not the other way around. That's why Apple made it easy for UIViewController to find a table cell, and difficult to do what you are trying to do.

Give us more details on what you are trying to do if you can't figure out how to reverse your logic.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 05-01-2011, 12:11 AM   #11 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: New Zealand
Posts: 49
jvpython is on a distinguished road
Send a message via Skype™ to jvpython
Default

Yes thanks that helped me a lot. Ive got my methods working now
jvpython is offline   Reply With Quote
Reply

Bookmarks

Tags
class, iphone, uitableviewcell

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: 333
11 members and 322 guests
dansparrow, iOS.Lover, lorrettaui53, MikaelBartlett, Nobbsy, oztemel, pbart, PlutoPrime, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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