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 :-)
Related
In my app, I am using tableview and cell in this which is tableview too. All things work good but when I want to handler selected cell on tableview which is a cell but i don't control
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
This function call at tableview parent only. But in my case, i want to call this function in both of tableview (parent tableview and tableview in cell).
Thanks!
Did you imported UITableViewDelegate? and add it to you table view as self.tableView.delegate = self,Better to check once!
Inside the table view of the cell, please set the delegate and datasource as the cell views reference.
As I think, your parent tableView get the select action and block the child table view from receive this action. I think there're two or more approaches to resolve this:
1. Change your view hierachy (contruct) of your view (don't make detail table view as a cell of the parent table). Make the detail table view as top view, so it could received select action, then maybe, pass this action to (parent) tableview.
2. Add UIGestureRecognizer to both child tableView and parent tableView, then check to perform tap action to both of them
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch
I am learning objective c and I'm following this tutorial here:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
Whenever I create a table cell view, It creates an extra content view that makes it impossible to link my labels, images to the cell. How Can I delete the extra content view and link my objects?
Here is a screenshot showing what I mean...
Getting an Error with this code... use of undeclared identifier on cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MingleViewCell *cell = (MingleViewCell *)[[tableView dequeueReusableCellWithIdentifier:#"MingleViewCell"]];
LocalPerson *local = [self.people objectAtIndex:indexPath.row];
cell.nameLabel.text = local.name;
cell.aboutMeLabel.text = local.game;
return cell;
}
Relax. From the docs:
The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.
This is how it's done, the content view should be there and you should be able to connect IBOutlets/IBActions normally by ctrl-dragging from your elements added to the cell in the storyboard into the custom cell class code.
you should not delete the content view which you are calling is extra. If you see UITableViewCell has a property contentView by default in which you add all the other content like UIButton, UILabel, etc. It's this contentView which is the main container.
So whenever you inherit any class from UITableViewCell, that class also has this contentView. So instead of deleting it you can use it as a container and add other elements.
I'm trying to get a UIScrollView to work correctly inside of a UICollectionViewCell.
The custom cell is being loaded in via a xib file and is a subclass of UICollectionViewCell. I had problems getting other controls working, such as a button and a gesture recognizer since the UICollecitonView doesn't seem to be passing any touches to the cells, but I got around those with gesture recognizers on the UICollectionView itself. The one remaining issue I have is the UIScrollViews...
The UICollectionView scrolls horizontally, and the UIScrollView in the cells scroll vertically. I've tried using a UIPanGestureRecognizer to scroll them, but that seems to disable the UICollectionView's ability to scroll.
Anybody have any thoughts?
EDIT: Got it!
So I had converted to a collection view from a previous third party library we were using before iOS6. Turns out the problem was with the xib files we were using for the cells. With the library before, the cells were just subclasses of UIViews. I changed the classes to subclass UICollectionViewCell, and updated the Custom Class. Turns out this was not enough. In order for touches to get passed to the cells I needed to actually had to drag in a new UICollectionViewCell from the Object library, copy over all the subviews and reconnect the IBOutlets. After this, it worked!
I fixed this in my code by making sure resizing of the scroll view happens on main thread.
My collection view is using nsfetchedresultscontroller that is using block calls to refresh selected cells. On the first time a cell was selected the scrollview would not scroll. However if you clicked on another cell and clicked back it would work fine. The initial load of the cell seemed like size calc might not be where it needed to be on main thread to affect behavior.
-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"CustomCell" forIndexPath:indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
// resizeScrollViewMethod should be where scrollview content size > scroll view frame.
[cell resizeScrollViewMethod];
});
return cell;
}
- (void) resizeScrollViewMethod {
//Do your scrollview size calculation here
}
No problem with UISCrollView in UICollectionViewCell. Use StoryBoard and you'll scroll OK.
UIScrollView overlay UICollectionViewCell, so that didSelect work only when tap outside ScrollView and inside Cell (scrollView.frame < cell.frame).
If you want to implement tap or other gesture, just add it to UIScrollView in awakeFromNib
Refer code:
https://github.com/lequysang/github_zip/blob/master/CollectionViewWithCellScrollViewStoryBoard.zip
I have a Storyboard which contains a UITableViewController. The table view is static and contains two sections. The table view was setup entirely in IB (including the header and footer text of the table view sections) - I have not implemented any table view delegate methods in my view controller.
If I attempt to get a reference to the UITableViewHeaderFooterView for a given section it always returns nil.
UITableViewHeaderFooterView* header =[self.tableView headerViewForSection:0];
When I run the app I can see the header and footer text that I set in IB so I know those views are there. I just can't figure out how to access them programmatically.
Any help would be much appreciated,
CS
Actually you'll need to specify the table footer view, and pass it to the table view using its delegate.
For example, suppose you have defined a IBOutlet UIView named tableFooterView.
Then in the following delegate method, you can pass your tableFooterView to your table view:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default or specified footer height
{
return self.tableFooterView;
}
Also you'll need to implement the following method to set the height of the table footer view:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return self.tableFooterView.frame.size.height;
}
I've subclassed UITableViewCell to display a UIImage and two UILabel subviews. In the view controller for the table view, in the method cellForRowAtIndexPath: I've enabled an accessory view via setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton.
Cells display correctly.
When I tap on the accessory disclosure button I want to replace the two label subviews with two different label subviews. My approach was the following:
In the subclassed UITableViewCell, inside layoutSubviews, create the
CGRects for the "alternate" labels, position them in the same
places as the two "original" label and hide them via setAlpha:;
When the disclosure button is tapped swap out the set of two
label by adjusting their respective alphas.
The problem is I can't figure out what logic in layoutSubviews I'd use to know whether the accessory button has been tapped. I see that in the view controller accessoryButtonTappedForRowWithIndexPath: is called when that button is tapped and from there it seems like I would call layoutSubviews but can't figure out how to use that fact to accomplish what I'm trying to do.
Am I going about this all wrong? Instead of hiding/showing CGRects with alpha should I simply be creating another subclass of UITableViewCell?
When I tap on the accessory disclosure button I want to replace the two UILabel subviews with two different UILabel subviews.
I'll do the following. Create a public method in your UITableViewCell subclass like the following:
- (void)changeContentForCell;
In this method you could set the contentView as you prefer.
Then in your view controller implement
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
CustomCell* cCell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];
[cCell changeContentForCell];
}
This is a simple example for change the content. In my opinion you don't have to use layoutSubviews to add views.
Leave this logic in changeContentForCell and then call setNeedsLayout to change your layout. Maybe you could have a variable that tracks the state for your cell: normal state or modified state.
Hope it helps.