iOS中的Xcode类名,没有应用程序名称前缀

问题描述 投票:2回答:1

我正在尝试使用此代码从xib加载UIView

NSString *className = NSStringFromClass([self class]);
_customView = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];

在另一个项目中,它工作正常,但在我的新项目中,className返回"myapp.MyClassName"。我不知道为什么要添加应用程序名称“ myapp”。类名之前的前缀。我没有名为"myapp.MyClassName.xib"的笔尖,因此应用程序崩溃时带有>>

Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/XXXX-XXXX/myapp.app> (loaded)' with name 'myapp.MyClassName''

我有:

  • 用于初始化_customView的CustomXibUIView类(目标C)
  • 继承自CustomXibUIView的MyClassName类(Swift)(用于初始化程序)
  • MyClassName.xib
  • 我正在使用XCode6-Beta5,iOS SDK 8.0,部署目标是iOS7 +

如何获得没有前缀的清晰的班级名称?

我正在尝试使用以下代码从xib加载UIView:NSString * className = NSStringFromClass([self class]); _customView = [[[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] ...

ios objective-c xcode swift xib
1个回答
4
投票

这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.