Storyboard init
bgottsch opened this issue · 7 comments
Is there another way to initialise the ChatController without using the [ChatController new]? I'm trying to use storyboard to do so by setting the class of the view to ChatController but when i run the app it doesn't initialise the ChatController.
Thanks in advance and great work.
This is not an issue with the ChatController, which is why I closed it. I'd still like to help you get it working, I just don't think its an issue with the control itself.
[ChatController new];
Is just a shorthand I like, you can call it also with:
[[ChatController alloc]init];
Can you show a link to your project so I can take a look at what's going on?
If you're trying to make ChatController
a UIView
this will not work. You can use ChatController.view
if you need to make special access to the view, but this might provide strange results so you'd have to play with it.
Also remember that if you like a control, adding a star is an easy way to show support and encourage updates!
Best,
Logan
Ok, I understand what you were talking about now, and I figured out what's going on. I do some of my loading in the
initWithNibthat isn't running when launching from storyboards. Replace
initWithNibName:and
viewDidLoadwith the following code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Custom initialization
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
// TopBar
_topBar = [[TopBar alloc]init];
_topBar.title = @"Chat Controller";
_topBar.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
_topBar.delegate = self;
// ChatInput
_chatInput = [[ChatInput alloc]init];
_chatInput.stopAutoClose = NO;
_chatInput.placeholderLabel.text = @" Send A Message";
_chatInput.delegate = self;
_chatInput.backgroundColor = [UIColor colorWithWhite:1 alpha:0.825f];
// Set Up Flow Layout
UICollectionViewFlowLayout * flow = [[UICollectionViewFlowLayout alloc]init];
flow.sectionInset = UIEdgeInsetsMake(80, 0, 10, 0);
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
flow.minimumLineSpacing = 6;
// Set Up CollectionView
CGRect myFrame = (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]statusBarOrientation])) ? CGRectMake(0, 0, ScreenHeight(), ScreenWidth() - height(_chatInput)) : CGRectMake(0, 0, ScreenWidth(), ScreenHeight() - height(_chatInput));
_myCollectionView = [[UICollectionView alloc]initWithFrame:myFrame collectionViewLayout:flow];
//_myCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
_myCollectionView.backgroundColor = [UIColor whiteColor];
_myCollectionView.delegate = self;
_myCollectionView.dataSource = self;
_myCollectionView.indicatorStyle = UIScrollViewIndicatorStyleDefault;
_myCollectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 2, 0, -2);
_myCollectionView.allowsSelection = YES;
_myCollectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_myCollectionView registerClass:[MessageCell class]
forCellWithReuseIdentifier:kMessageCellReuseIdentifier];
// Register Keyboard Notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
I've modified your sample project with my class. Its very rudimental and it may be a simple mistake of mine. Thanks again for the fantastic controller and for your support.
Worked perfectly. Thanks.
Glad it's working!
I haven't decided if I want to add this to the master branch yet, but if I do, I'll make sure to include your name in the credits. I won't have time to run full tests right now, but I'll try and get to it when my schedule opens up a little. Good luck with the rest of your project!
Best,
Logan
Maybe create a second branch for storyboard init support. I would add it since storyboard is becoming more and more popular. Also, I don't see any issues from these changes since it the viewDidLoad method is always called.
If you need any help, feel free to ask.
Beno
Good Idea Beno,
I went ahead and created a new branch for now, that way I can merge it into the master later. I don't think there should be a problem with the fix overall, I just get a little bit paranoid and like to be extra safe in making sure I'm not forgetting something before I publish it. Once I feel confident, I'll merge it.
Here's the current storyboards branch
Best,
Logan