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 07-08-2010, 07:04 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 7
willmeister is on a distinguished road
Default Simple Inheritance Question.

The SDK tells me that UIBarButtonItem inherits from UIBarItem. That should mean that a UIBarButtonItem should have an associated tag property.

The problem for me is that Xcode is telling me that tag, title and other properties are *NOT* available for UIBarButtonItem.

I even ran the program with

NSLog(@"class: %@", [item class]);

to make sure I was actually using the correct class. It outputs:

class: UIBarButtonItem

I don't understand why I'm getting the compile error "Request for member "tag" ... et cetera."

What simple mistake am I doing/missing please? I'm about to go insane.

-- Edit --

Believe I figured out a workaround, I set my method to (IBAction) selection: (UIBarButtonItem *) sender. I always thought you could compile anything with any message to id and would only crash at runtime.

Last edited by willmeister; 07-08-2010 at 07:10 PM.
willmeister is offline   Reply With Quote
Old 07-08-2010, 10:16 PM   #2 (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 willmeister View Post
The SDK tells me that UIBarButtonItem inherits from UIBarItem. That should mean that a UIBarButtonItem should have an associated tag property.

The problem for me is that Xcode is telling me that tag, title and other properties are *NOT* available for UIBarButtonItem.

I even ran the program with

NSLog(@"class: %@", [item class]);

to make sure I was actually using the correct class. It outputs:

class: UIBarButtonItem

I don't understand why I'm getting the compile error "Request for member "tag" ... et cetera."

What simple mistake am I doing/missing please? I'm about to go insane.

-- Edit --

Believe I figured out a workaround, I set my method to (IBAction) selection: (UIBarButtonItem *) sender. I always thought you could compile anything with any message to id and would only crash at runtime.
You are right about inheritance and UIBarButtonItem. A UIBarButtonItem should indeed have all the properties and methods that a UIBarItem does, because it is a subclass.

Can you post the offending code (before your work-around) along with the exact error you are getting from XCode?
__________________
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 07-08-2010, 11:55 PM   #3 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Before your workaround, your code probably looked something like this:
Code:
(IBAction) selection: (id) sender
{
    ...
    <blah blah> sender.tag <blah>
    ...
}
Because the parameter 'sender' is of type 'id', the compiler essentially knows nothing about it. It certainly isn't aware that it might have a 'tag' property, and so it emits a warning or error. When you change the 'sender' parameter type to 'UIBarButtonItem', the compiler now knows everything you can and can't do with 'sender'.

An alternative to your workaround is to simply cast 'sender' to the data type you know it is, like this:
Code:
(IBAction) selection: (id) sender
{
    UIBarButtonItem * myBBI = (UIBarButtonItem *)sender;

    ...
    <blah blah> myBBI.tag <blah>
    ...
}
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Reply

Bookmarks

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: 330
14 members and 316 guests
akphyo, cgokey, EXOPTENDAELAX, flamingliquid, GHuebner, guusleijsten, Mirotion22, ohmniac, Paul Slocum, PavelSea, Pudding, SLIC, Sloshmonster, Sonuye857
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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