常见错误汇总

第一启动界面

Failed to instantiate the default view controller for UIMainStoryboardFile ‘Main’ - perhaps the designated entry point is not set?
原因分析:在StoryBoard中没有一个view controller设置了Initial Scene。
解决方案:在Storyboard中,选择一个view conroller作为story board的第一启动界面

20141202141656125

CollectionViewLayout

* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘UICollectionView must be initialized with a non-nil layout parameter’**

原因分析:在UICollectionView中没有CollectionViewLayout
解决方案:创建一个CollectionViewLayout

- (id)init
{
    // 1.流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    // 2.每个cell的尺寸
    layout.itemSize = CGSizeMake(80, 80);
    // 3.设置cell之间的水平间距
    layout.minimumInteritemSpacing = 0;
    // 4.设置cell之间的垂直间距
    layout.minimumLineSpacing = 10;
    // 5.设置四周的内边距
    layout.sectionInset = UIEdgeInsetsMake(layout.minimumLineSpacing, 0, 0, 0);
    return [super initWithCollectionViewLayout:layout];
}

按钮不能设置Image

创建一个UIButton后,可以设置背景图片,但是不能设置image.
原因分析:可能因为按钮的Type为系统样式.

解决方案:将按钮的Type设置为Custom.

属性名以New开头

某个控件的属性名称以New开头,编译错误
原因分析:New系统会认为创建新对象.

解决方案:不以New开头的名称来命名对象.

调用super init报错

在某个-(id)initwith中调用[super init]报错
原因分析:当前对象的构造方法不是以init开头,而是以initwith开头.

解决方案:init后面任何单词手写字母大写.

xcode 编写代码不能智能提示

代码块不能提示,但是可以搜索拉出.
解决方法:Window(menu) -> -> Projects(tab),删除 Derived Data ,立刻关闭xcode 然后重启xcode然后重新打开项目。