Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

iphone - [UILabel copyWithZone:]: unrecognized selector sent to instance

I feel like I'm banging my head against the wall here (and I'm ready to do that, frankly).

I'm trying to set a background to the view. Background I need to set is an image and I'm using this code (which works perfectly fine in two other UIViewController subclasses - this was a copy/paste into the new file):

UIImage *img = [gameNode imageFromKey:@"background"];
UIColor *bg = [[UIColor alloc] initWithPatternImage:img];
self.view.backgroundColor = bg;
[bg release];

As I said, this works perfectly fine in two other places, however here, line self.view.backgroundColor = bg throws

'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x9259840'

There's not much more to go by. I verified in IB that the top-level view's referencing outlet is set to the File's owner. I cleaned the project and restarted. I even closed Xcode and restarted it again - no luck. What else am I missing?

Edit: As I mentioned, there's not much back stack trace, just this:

2012-05-28 13:13:56.997 OOKL[36012:17303] -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x92b79a0
2012-05-28 13:13:56.997 OOKL[36012:17303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x92b79a0'
*** First throw call stack:
(0x2933052 0x44c7d0a 0x2934ced 0x2899f00 0x2899ce2 0x2935bd9 0xaa92dd 0x6a4f40 0x6a4eeb 0x6bfd60 0xc0191a 0x2934e1a 0x289e821 0xc0046e 0xaa7e2c 0xaa83a9 0xaa85cb 0xb2b59 0xb1969 0x2934ec9 0x9e55c2 0x9e555a 0xa8ab76 0xa8b03f 0xa8a2fe 0xa0aa30 0xa0ac56 0x9f1384 0x9e4aa9 0x2ac6fa9 0x29071c5 0x286c022 0x286a90a 0x2869db4 0x2869ccb 0x2ac5879 0x2ac593e 0x9e2a9b 0x214d 0x20c5)

Nothing else - before or after.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I guess this was one of those weird bugs with Xcode that you can't trace or reproduce every time. I narrowed the issue down to one specific UILabel in the IB. As soon as I connect it to an IBOutlet UILabel *, I get this error.

On further investigation, it turns out that name title was causing the issue. I had the label declared as

IBOutlet UILabel *title;

As soon as I changed the name to gtitle, everything worked as expected. Who knows?..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...