开发者

Assigning the text label from a UIButton to a UILabel not working

I have this declared in the .h

IBOutlet UILabel *display;

and in the .m I am doing the following but its not working , keep saying that displat.text is null. Puzzled, help! Yes I am a noob.

NSLog(@"operation button pressed %@ is of class %@",[[sender titleLabel] text],[[[sender titleLabel] text] class] ); 
NSString *operation = [[sender titleLabel] text];
[display setText:operation];
NSLo开发者_高级运维g(@"display text is of class %@ and equals %@",[display.text class], [display text]);

I also tried like this:

NSLog(@"digit button pressed %@ is of class %@",[sender currentTitle],[[sender currentTitle] class] );
display.text = (NSString *)[[sender titleLabel] text];
NSLog(@"display text is of class %@ and equals %@",[display.text class], [display text]);


Two things to check:

  1. Make sure your "display" outlet is connected in Interface Builder.
  2. Make sure your interface is fully loaded before calling this code.

Regarding item 2, it's easier to give you advice if you let us know where this problem code is being called from (from what method). Is it an action or at startup? Where?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜