The error you're seeing is pretty clear. You're trying to dequeue a reusable view but the collection view doesn't know anything about the reuse identifier you're passing.
You need to call registerClass:forSupplementaryViewOfKind:withReuseIdentifier:
before dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:
is called. I typically call one of the register methods in viewDidLoad
so all the setup is done and I can just call the dequeue method. If you're loading your custom header and footer views from nib you can use the registerNib:forSupplementaryViewOfKind:withReuseIdentifier:
method.
Edit
I see you updated the code. You need to move these lines
UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init];
self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 390, 300) collectionViewLayout:layout];
above the lines where you're calling the register class methods. You cannot send messages to an object before you allocate and initialize it.