I have a problem when dequeuing a UICollectionView cell from the storyboard.
I have a view controller with a collection view as one of the subviews. The VC is set as the collection view's data source and delegate. The collection view has a couple of prototype cells with identifiers set.
When doing this:
- (void)viewDidLoad {
[super viewDidLoad];
self.sizingCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:#"CellId" forIndexPath:nil];
}
I get an EXEC_BAD_ACCESS on the self.sizingCell line.
Interestingly, when I created a new test project with a view controller containing a collection view and did the same thing in viewDidLoad, the collection view's cell was created with no issues.
Did anyone else run into a similar issue?
Related
I put the iCarousel View in a table View and try to scroll the iCarousel, but the problem is it's not scrollable at all.
I can see iCarousel in the cell like following:
and I put iCarousel datasource and delegate in the tableView Controller, create a customer function to set the iCarousel datasource and delegate.
In the CustomTableViewCell I just define the setting delegate function:
- (void) setICarouselDataSourceDelegate: (id<iCarouselDelegate,iCarouselDataSource>)dataSourceDelegate {
self.carousel.dataSource = dataSourceDelegate;
self.carousel.delegate = dataSourceDelegate;
[self.carousel reloadData];
}
and in the MainTableView, I call the DataSourceDelegate in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
First of all iCarousel is not any standarad View ... you should put link of the control that you're using
Second it seems like iCarousel is uses UIScrollView and UITableView is also derived from UIScrollView It's never a good idea to put a scrollview inside another scrollview.
This might be the reason why your table view is not scrolling.... BTW are you talking about horizontal scrollign or vertical scrolling ?
Currently I am using the iCarousel in Table View cell and it scrolls easily.
Just add standard view to cell in Storyboard.
In IB mark the class of that view to iCarousel.
Furthermore !ENABLE! user interaction on that view. (Maybe because of that you can't scroll the content inside the cell)
Implement separate datasource & delegate for every cell. (It is more clear which data are loading in the cell and also the cell itself can handle the data. You just pass the data to cell and it handles it accordingly.) - But it depends on you if you want to let one class to handle two separate control datasources & delegates :-)
I have custom cell on my table view which I've created with nib file. I have there 2 horizontal scrollViews. Target platform is iOS 7.
On Cell XIB file I've created "constrants" for every tableView (because I'm using autolayout).
On my Custom cell implementation file I have such code:
-(void)layoutSubviews
{
self.SwitchPageSV.contentSize = CGSizeMake(960, 240);
self.SwitchPageSV.scrollEnabled = YES;
self.SwitchPageSV.delegate = self;
self.ButtonsSV.contentSize = CGSizeMake(400, 40);
self.SwitchPageSV.scrollEnabled = YES;
}
And it is working like a charm. But when I go from this table view to other View Controller and go back, scroll view does not work anymore. I have to scroll my tableView to recreate cell and than it is working again.
Reloading data doesn't help:
I was trying to define those values on:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
on my viewController, where I'm putting all data to this cell. But from there, my settings for scroll view are not working at all. I have no idea what to do with that thing. Any help?
This is because layoutSubviews method in your code only invokes after initialization. But you need to execute the code inside this method even after coming back. For this you have to call setNeedsLayout
[self setNeedsLayout ];
I got my collectionview of photos to change layout with the following code:
newLayout = [[SDCGalleryLayout alloc] init];
and then
[self.collectionView setCollectionViewLayout:newLayout animated:YES];
It works fine and it animates from one layout to another. However, the view inside my collectionviewcell is not resizing to account for its new cell size. drawRect() of the views inside the collectionviewcell is not being called.
Any suggestions to get the views inside my collection cells to redraw after changing a layout?
Thanks
use -(void)layoutSubviews of the UIView inside the collection view cell. Works like a charm
This is my first time using nib files, and I am using them because I was to toggle two views without bloating the storyboard for easy UI editing. I went with child view controller's so I could separate everything. One of the child controller's will contain table view delegate and data source. So I created a nib with a single view in IB. I dragged in a table view, but it is already doing something odd.
Here is what a table view dragged into a storyboard view controller looks like:
And here is what it looks like in the nib file:
It still has the default California data in it. Why doesn't it say "Table View Prototype"?
I tried to add a cell to it anyway but I couldn't. The first image is what normally happens, the cell is nested. In the nib, though, it won't go into the table view.
I want to make the table view with custom cells, but I don't know what is wrong or if I am missing something since this is my first time using nibs.
It still has the default California data in it. Why doesn't it say "Table View Prototype"?
Because prototypes are a feature of storyboards only - not nibs.
I tried to add a cell to it anyway but I couldn't. The first image is what normally happens, the cell is nested. In the nib, though, it won't go into the table view.
To use a nib-designed cell type with a table view that doesn't come from a storyboard, you must have a separate nib for just the cell (there must be nothing else in the nib). Register the nib with the table view (in code); from then on, when you dequeue a cell, the table view will load the cell from the nib. See this section of my book:
http://www.apeth.com/iOSBook/ch21.html#_custom_cells
It's normal that you cannot nest a Table View Cell inside a Table View in a xib file. One possible approach to custom cells with xib files is to create a subclass of UITableViewCell and set it as the file owner of your custom cell in the xib file (create a xib file for the cell). Then you will be able to create outlets between UI elements in your custom cell and your custom UITableViewCell subclass.
In the following example, I'll use MyCustomCell as the name of the xib file containing the cell, and also the name of the custom class derived from UITableViewCell.
To register the cell with your table view, put this in your UITableViewController subclass:
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *cellNib = [UINib nibWithNibName:#"MyCustomCell" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:#"MyCustomIdentifier"];
...
}
Finally, in your tableView:cellForRowAtIndexPath: method you can dequeue a custom cell using its identifier and set its visual properties using the outlets you created before:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyCustomIdentifier"];
// Configure cell using its outlets
return cell;
}
I have put an UITableView inside a UIViewController and have copied code from UITableViewController over to my UIViewController to have it fulfill "Table data protocols" with UITableViewControllers default implementation and am following http://developer.apple.com/library/IOs/#documentation/UserExperience/Conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW10s chapter "Creating a Table View Programmatically" (with using ViewDidLoad instead of LoadView as I use IB and have a nib, I created an outlet for the UITableView named tableView).
Now in above links chapter the UITableView is assigned to self.view which is the UIView property of the UIViewController. Then scrolling the UITableView is working but the UITableView fills the entire screen hiding other view content such as an UIToolbar - probably as it is the sole content after being assigned to the view property.
If I omit the assignment, the other view content is in place an everything is sized properly, however the UITableView doesn't scroll.
How do I achieve scrolling of the UITableView inside an UIViewController with the UIVC having static content (such as a toolbar)?
Here's the relevant code:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
//self.view = tableView;
}
If you have other content in the view controller that you are adding in interface builder then this will be part of the UIViewController's .view property - when you assign the table view to this, you are removing all that content.
If your table view is appearing normally but is not scrolling (how about selection? Does that work?) you may have disabled user interaction on it.
You have mentioned in comments that there is nothing but empty cells in your table view - I think this is the cause of your problem. I have just created a sample project where I have added in a table view as a subview of the view controller's view, and scrolling is fine - this is with me populating 100 dummy rows in there. If I don't return anything for the datasource and delegate methods, then the table view does not scroll.