我收到以下错误消息:
2011-02-11 14:47:13.815 myProject[13177:207] Could not load the "icon-troubleshoot.png" image referenced from a nib in the bundle with identifier "com.myCompany.myProject"
Run Code Online (Sandbox Code Playgroud)
此文件是以前使用过的旧文件,但现在已被删除.据我所知,icon-troubleshoot.png在我的项目中没有使用过任何地方.我尝试清理和重建,清空缓存,但它没有用.搜索字符串疑难解答作为文本引用并选择"包含"返回任何内容.有谁知道我怎么能找到导致这个错误的原因?
我有一个动态单元格UITableViewController,我想在有人点击一个单元格时推送一个特定的View Controller.所以我试图使用预先制作的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但当我进入模拟器并点击一个单元格时,这就是我得到的:
"NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle [...] with name 'AffichageVotesQuestionDuMomentViewController'.
Run Code Online (Sandbox Code Playgroud)
在方法中,我有这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
AffichageVotesQuestionDuMomentViewController *detailViewController = [[AffichageVotesQuestionDuMomentViewController alloc] initWithNibName:@"AffichageVotesQuestionDuMomentViewController" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
AffichageVotesQuestionDuMomentViewController是我自己创建的自定义视图控制器.我也尝试创建另一个随机的,我得到相同类型的错误.如果我设置initWithNibName:为nil,它会转移到顶部有导航栏的视图控制器,但那是完全黑色的.
现在,我是一个初学的iPhone程序员,对笔尖,笔尖等名称的理解很差.任何帮助表示赞赏.此外,我没有在故事板或任何事情中做任何segue,因为它似乎是我以编程方式创建视图控制器并推动这种方式.如果有一个很好的方法可以用segue做到这一点,我也没关系(但我需要知道敲击单元格的行).
谢谢!
从nib文件加载UIView时,视图通常translatesAutoresizingMastIntoConstraints设置为YES.
因此,您无法向视图添加顶级约束(例如宽度和高度).
在过去,我已经能够生成一个顶级视图,它允许我创建顶级约束,并设置translatesAutoresizingMastIntoConstraints为NO.
如何从笔尖加载UIView而不进行子类化时,我怎么能得到这种行为?
因此,我创建了一个自定义抽象类,该抽象类继承自UIViewController(由RebloodViewController继承)名为MainViewController的类。在这一节课中,我写了一个可重用的笔尖注册函数
class MainViewController: RebloodViewController {
typealias Cell = RebloodViewController.Constants.Cell
internal func registerNib(_ cellNib: Cell.Nib, target: UICollectionView) {
let nib = UINib(nibName: cellNib.rawValue, bundle: nil)
do {
let identifier = try getCellIdentifierByNib(cellNib)
target.register(nib, forCellWithReuseIdentifier: identifier)
} catch {
fatalError("Cell identifier not found from given nib")
}
}
private func getCellIdentifierByNib(_ nib: Cell.Nib) throws -> String {
var identifier: String? = nil
switch nib {
case .articles:
identifier = Cell.Identifier.articles.rawValue
case .events:
identifier = Cell.Identifier.events.rawValue
}
guard let CellIdentifier = identifier else …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我创建的自定义视图。
我使用笔尖实例化,但它会导致无限循环,我不知道如何修复。任何想法?
这是运行结果的图像:
这是导致问题的代码:
// MARK: - Init & Setup
// Needed for IBDesignable
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup(){
view = loadViewFromNib()
view.frame = bounds
view.autoresizingMask = UIViewAutoresizing(rawValue: UIViewAutoresizing.RawValue(UInt8(UIViewAutoresizing.flexibleWidth.rawValue) | UInt8(UIViewAutoresizing.flexibleHeight.rawValue)))
addSubview(view)
}
func loadViewFromNib() -> UIView{
let bundle = Bundle(for:type(of: self))
let nib = UINib(nibName: "LoginView", bundle: bundle) // TEST: changin bundle from bundle-> nil
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
return …Run Code Online (Sandbox Code Playgroud) 我创建了一个自定义视图,从nib加载其内容,如下所示:
/* PricingDataView.h */
#import <UIKit/UIKIt.h>
@interface PricingDataView : UIView {
UIView *contentView;
}
@property (nonatomic, retain) IBOutlet UIView *contentView;
@end
/* PricingDataView.m */
#import "PricingDataView.h"
@implementation PricingDataView
@synthesize contentView;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
[[NSBundle mainBundle] loadNibNamed:@"PricingDataView" owner:self options:nil];
[contentView setFrame:frame];
[self addSubview:contentView];
}
return self;
}
/* ... */
Run Code Online (Sandbox Code Playgroud)
在nib文件中,我设置PricingDataView为文件所有者的类型,并连接contentViewIB中的插座.我将UIView接口库中的常规放置到显示给用户的全尺寸视图,然后将其类名更改为PricingDataView.它全部构建,但在运行时,我的自定义视图应该是什么都没有呈现.
我把断点放进去PricingDataView.initWithFrame,但它们没有击中,所以我知道我错过了会导致视图被初始化的东西.我很好奇的是,在从nib加载我的其他视图的过程中,所有的初始化都发生在我身上,但不是这个.为什么?
我有一个nib文件,我在我的应用程序中的某个点加载.将NSWindow IBOutlet从我的AppDelegate链接到第二个nib文件的窗口是否合法?换句话说,我的IBOutlet没有连接到Xcode默认创建的MainMenu xib文件.如果这是合法的,我可以访问NSWindow的框架和其他功能吗?
所以我正在编写一个应用程序,我希望它是通用的.当我创建项目时,我创建了一个通用应用程序.我已经编写了所有的iPhone代码,并且有10个类.现在我要创建iPad版本.我想基于设备类型加载不同的Nib,而不是拥有两组基本上完全相同的代码.
我尝试在app委托中使用BOOL并且遇到了麻烦.我在mainViewController类中尝试了设备检查,(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 我根据设备类型返回了一个不同的nib.但我只能得到iPhone版本或空白笔尖.在此先感谢您的帮助.
作为一个初级开发人员,我想知道使用Storyboard与.nib文件构建应用程序界面的优缺点.
我知道:
但是,我想问一下有经验的人,使用一种方法而不是另一种方法可能会出现无法预料的缺点或优点,以及经验丰富的开发人员建议开始使用的方法.(我将开发用于个人和商业用途.)
非常感谢你!
对不起,我对xcode很新,有一个非常大的项目.我将xcode升级到4.3.我有一个项目(不使用故事板),我需要添加一个带有nib文件的视图控制器.
在升级之前我做了File - > Ne File - > Cocoa Objective-C子类和xcode为我创建了m/h及其nib文件.现在该选项消失了,我该如何添加视图控制器?
我创建了Objective-C类,并且单独创建了一个nib文件,但是如何将H/m文件链接到nib?
怎么m文件调用是nib?
你能帮帮我吗?该项目非常大,我可以使用storyboard选项重写代码!谢谢
nib ×10
iphone ×5
objective-c ×4
ios ×2
swift ×2
xcode ×2
xib ×2
autolayout ×1
cocoa ×1
cocoa-touch ×1
ipad ×1
macos ×1
nswindow ×1
swift3 ×1
uitableview ×1
uiview ×1
unit-testing ×1
views ×1
xcode6 ×1