小编Ris*_*pat的帖子

如何添加 UICollectionView 标题

我希望以编程方式向我的 UICollectionView 添加一个标签,并使用 viewForSupplementaryElementOfKind 和 referenceSizeForHeaderInSection 来设置它,但是由于某种原因,当我设置我的视图时,它仍然将它放在我的 CollectionView 的第一行中,而不是创建的标题。正如您在此屏幕截图中看到的,“今天”在第一个单元格中,而不是我为其创建的标题

class TvController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

private let cellId = "cellId"
private let headerId = "headerId"

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.title = "TV"
    navigationController?.navigationBar.isTranslucent = false

    collectionView?.backgroundColor = .white

    collectionView?.register(TvCell.self, forCellWithReuseIdentifier: cellId)
    collectionView?.register(Header.self, forCellWithReuseIdentifier: headerId)

}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 10
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath)

    return cell …
Run Code Online (Sandbox Code Playgroud)

iphone ios swift

5
推荐指数
1
解决办法
1万
查看次数

NSUnknownKeyException ios目标C.

我为我的ios应用程序创建了一个幻灯片抽屉..幻灯片抽屉工作得很好...我在幻灯片抽屉中有几个按钮和一个文本框...问题是每当我尝试添加对按钮/文本框的引用时在幻灯片抽屉里,我得到了NSUnknownKeyException ...我不知道如何解决这个问题,因为我在IO中很新...包括下面的代码......

SlideDrawer.h

#import <UIKit/UIKit.h>

@interface SlideDrawer : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *home;
- (IBAction)homeclick:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)

SlideDrawer.m

#import "SlideDrawer.h"
@interface SlideDrawer ()
@end
@implementation SlideDrawer
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
 - (IBAction)homeclick:(id)sender {
}
@end
Run Code Online (Sandbox Code Playgroud)

MainViewController.h

#import <UIKit/UIKit.h>

@interface mainViewController : UIViewController{
UIView *menuDrawer;
}

@property (readonly, nonatomic) UISwipeGestureRecognizer     *recognizer_open, *recognizer_close;
@property (readonly, …
Run Code Online (Sandbox Code Playgroud)

objective-c ios nsunknownkeyexception

1
推荐指数
1
解决办法
939
查看次数

标签 统计

ios ×2

iphone ×1

nsunknownkeyexception ×1

objective-c ×1

swift ×1