开发者

How to Declare Nib file?

How to declare nib file with initwithnib syntax It display 'Warning: passing argument 1 of initwithNibName:bundle: from Incompatible pointer type'.

my statement is:

SpanishViewController *spanishview = [[SpanishViewController alloc] 
    initWithNibName:"LocalizeMeViewC开发者_JAVA百科ontroller.xib (es)" 
             bundle:[NSBundle mainBundle]];

Thanks in Advance........


Unless you really know what you're doing with custom NIB filenames, you should be loading NIBs like this:

self.myViewController = [[[MyViewController alloc] initWithNibName:nil bundle:nil] autorelease];

or:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];

Apple is liable to add some new feature in the future, unannounced, that depends upon this "I don't care, choose the NIB automatically, please" feature.

PS: "incompatible pointer type" means you tried to pass it a variable of the wrong "type". You probably wrote:

[... initWithNibName:"name" bundle:nil]

... i.e. forgot the "@" symbol. That turns it into a different type/pointer type to what is expected (a particular kind of string pointer).


EDIT: now that you've added your actual code, I suspect you're doing localization the wrong way. Check the Apple docs, but off the top of my head, you provide multiple copies of the same NIB with identical name, but stored in different sub-directories, one per language.


You are probably not putting the exact name of your xib. I wouldn't recommend putting parentheses on a Nib name. And as Adam said, you need to put a '@' before it, since it is still a NSString it gets as a parameter. So the name should be a NSString. @"myNibName"


Just do:

SpanishViewController *spanishview = [[SpanishViewController alloc] 
initWithNibName:@"LocalizeMeViewController" 
         bundle:nil];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜