开发者

Move controls programmatically in a method warns 'method not found' and 'control may not respond to'

I have a UISegmentedView that I use to present the user with an option on one of two calculations they can do in my program. If the segmented control is one way, it should show 4 text boxes and their labels, if the other only 3 (and the calculation would change as well).

This all works, my problem is with moving the controls (I want to hide the ones you won't need, as well as move the controls on the screen to make it look nice)

I would like to put this in one method, and just pass the UIControl to move it. For example, in my .h

-(void) moveControlUp:(UIControl*)controlToMove;

Then, in my .m

- (void)moveControlUp:(UIControl*)controlToMove
{
    controlToMove.frame = CGRectMake(controlToMove.frame.origin.x, controlToMove.frame.origin.y - 39, controlToMove.frame.size.width, controlToMove.frame.size.height); 
}

and then when I actually want to move the controls (labelPointsHeader is a UILabel, textPointsName is a text box):

开发者_如何学Go
[labelPointsHeader moveControlUp];
[textPointsName moveControlUp];

This doesn't work, and I get two errors. "UILabel may not respond to '-moveControlUp'" and "Method '-moveControlUp' not found (return type defaults to id). I crash when I hit this, stating that 'unrecognized selector sent to instance'.


In which class did you define these methods? (doesn't appear to be a category)

Let's say you defined them in SomeClass, then you need to do this:

[someInstanceOfSomeClass moveControlUp:labelPointsHeader];

Right now you are sending a message to a UILabel in the first case, but UILabel does not have this method. The method is in whichever class you defined it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜