positionについて調べる – 解決編
公開日:
:
最終更新日:2013/11/12
cocoa
記事内に広告を含む場合があります。記事内で紹介する商品を購入することで、当サイトに売り上げの一部が還元されることがあります。
以下、macosx-dev MLでのやり取り。
Hi Guys,
I wrote the following programs.
-(void)changeSelectedIndex:(NSInteger)theSelectedIndex
{
selectedIndex=theSelectedIndex;
if (selectedIndex == [names count]) selectedIndex=[names count]-1;
if (selectedIndex < 0) selectedIndex=0;
selectionLayer.position = [[[menusLayer sublayers]
objectAtIndex:selectedIndex] position];
};
When I Bild it, the following errors are output.
/Users/user/Desktop/CoreAnimationMenu/MenuView.m:160: warning:
multiple methods named '-position' found
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSScriptObjectSpecifiers.h:191:
warning: using '-(NSInsertionPosition)position'
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h:598:
warning: also found '-(CGPoint)position'
/Users/user/Desktop/CoreAnimationMenu/MenuView.m:160: error:
incompatible type for argument 1 of 'setPosition:'
/Users/user/Desktop/CoreAnimationMenu/MenuView.m:160: warning:
multiple methods named '-position' found
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSScriptObjectSpecifiers.h:191:
warning: using '-(NSInsertionPosition)position'
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h:598:
warning: also found '-(CGPoint)position'
/Users/user/Desktop/CoreAnimationMenu/MenuView.m:160: error:
incompatible type for argument 1 of 'setPosition:'
I appreciate any help.
akio
As the warnings say: there are several position accessors in the frameworks, and the compiler does not know which one to use. To avoid this warning you should type the selectionLayer, as in [(CALayer)[[menusLayer sublayers] objectAtIndex:selectedIndex] position]
Christiaan
I corrected the code as follows.
selectionLayer.position = [
(CALayer*)[[menusLayer sublayers]
objectAtIndex:selectedIndex] position];
Warning was not displayed.
Tyank you very mach.
なるほど、[]内でC++みたいにキャストしたりできるのか。