大佬教程收集整理的这篇文章主要介绍了ios – 为什么我必须在Apple sdk中没有任何IBOutlets时将IBOutlet标识符添加到我的委托?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@interface TNGalleryView : UIView @property (assign,nonatomiC) id <TNGalleryViewDelegate> delegate; @property (assign,nonatomiC) id <TNGalleryViewDatasource> datasource; @end
我可以在代码中分配它的委托,但是当我想在IB中分配委托时,我不能.我必须将我的代码更改为:
@interface TNGalleryView : UIView @property (assign,nonatomiC) IBOutlet id <TNGalleryViewDelegate> delegate; @property (assign,nonatomiC) IBOutlet id <TNGalleryViewDatasource> datasource; @end
然后我可以在IB中分配delegate和datasource.
为什么我想在IB中分配delegate和datasource我必须添加IBOutlet标识符,但在apple sdk里面没有任何IBOutlets?例如,UICollectionView声明的这一部分:
NS_CLASS_AVAILABLE_IOS(6_0) @interface UICollectionView : UIScrollView - (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout; // the designated initializer @property (nonatomic,retain) UICollectionViewLayout *collectionViewLayout; @property (nonatomic,assign) id <UICollectionViewDelegate> delegate; @property (nonatomic,assign) id <UICollectionViewDatasource> datasource;
没有任何IBOutlet,但我可以在IB中分配datasource并委托给它.
用文本编辑器打开你的storyboard / xib,搜索“TNGalleryView”,你会发现这样的xml标签:
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConsTraints="NO" id="ke7-rk-01e" customcatlass="TNGalleryView"> <rect key="frame" x="86" y="309" width="160" height="252"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <color key="BACkgroundColor" white="1" alpha="1" colorSpace="custom" customcatolorSpace="calibratedWhite"/> </view>
请注意:TNGalleryView包含在带有属性的“view”标记中:customcatlass =“TNGalleryView”
现在在storyboard / xib中添加一个UICollectionView,使用文本编辑器保存并重新编写storyboard / xib,搜索“collectionView”,你会发现这样的xml标签:
<collectionView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" minimumZoomScale="0.0" maximumZoomScale="0.0" dataMode="prototypes" translatesAutoresizingMaskIntoConsTraints="NO" id="ouM-xa-T6a"> <rect key="frame" x="93" y="72" width="160" height="252"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <collectionViewFlowLayout key="collectionViewLayout" minimumLinespacing="10" minimumInteritemSpacing="10" id="Cv0-O7-zGY"> <size key="itemSize" width="50" height="50"/> <size key="headerReferenceSize" width="0.0" height="0.0"/> <size key="footerReferenceSize" width="0.0" height="0.0"/> <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/> </collectionViewFlowLayout> </collectionView>
现在,您将发现不同的,collectionView包含在“collectionView”标记中
我想这就是为什么你不能在IB中分配自定义委托而不将自定义委托设置为IBOutlet的原因.
评论其他人的回答没有声誉.所以我在这里说些什么:清楚地阅读问题,并在xcode中进行测试,你会发现Sergey Demchenko的问题是:
首先,如果以这种方式声明TNGalleryViewDelegate:
@property (assign,nonatomiC) id <TNGalleryViewDelegate> delegate;
xcode屏幕截图:
现在,nonatomiC) IBOutlet id <TNGalleryViewDelegate> delegate;
xcode屏幕截图:
以上是大佬教程为你收集整理的ios – 为什么我必须在Apple sdk中没有任何IBOutlets时将IBOutlet标识符添加到我的委托?全部内容,希望文章能够帮你解决ios – 为什么我必须在Apple sdk中没有任何IBOutlets时将IBOutlet标识符添加到我的委托?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。