I am currently working on making a layout like a calendar. The basic idea is to add an UILabel and UICollectionView inside an UIScrollView, I am using just an UIViewController for layout(but with UICollectionViewDataSource and UICollectionViewFlowLayout delegate).
The scenario is: everytime a user searches data for a particular month(by clicking a button), the corresponding data would be given from the server and the UICollectionView frame would be set.
However, after I tried to update the frame of my UICollectionView, it happens that the collectionview will shift down in the UIScrollView, and I have no idea why this is happening. Have tried to set automaticallyAdjustsScrollViewInsets to 0 and used the [collectionView setContentInset] method, but it seems like not working out. Couldn't be more appreciate if anyone can give me some hint about this problem !
Below is some part of my code.
// viewDidLoad
self.weekLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.scrollView.frame.origin.y, self.calendarWidth, 20)];
self.calendarWidth = self.view.frame.size.width * 7 / 4;
self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.scrollView.frame.origin.y + 20, self.calendarWidth, self.scrollView.frame.size.height - self.weekLabel.frame.size.height * 7) collectionViewLayout:self.flowLayout];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
[self.collectionView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"collectionCell"];
[self.collectionView setBackgroundColor:[UIColor colorWithRed:241/255.0f green:239/255.0f blue:228/255.0f alpha:1.0f]];
// setup scrollView
[self.scrollView setContentSize:self.collectionView.bounds.size];
[self.scrollView addSubview:self.collectionView];
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(self.calendarWidth/7, (self.scrollView.frame.size.height - 40)/5);
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.currentMonthRange == 28 && self.selectedMonth == 2) {
return 28;
} else if ((self.currentMonthRange + self.currentWeekDay) > 35) {
return 42;
} else {
return 35;
}
}
// method that is called after getting data from server, update the frame
-(void) checkSpecialDay {
if (self.currentMonthRange == 28 && self.selectedMonth == 2) {
[self.collectionView setFrame:CGRectMake(self.view.frame.origin.x, self.scrollView.frame.origin.y + 20, self.calendarWidth, self.scrollView.frame.size.height - self.weekLabel.frame.size.height * 3)];
} else if ((self.currentMonthRange + self.currentWeekDay) > 35) {
[self.collectionView setFrame:CGRectMake(self.view.frame.origin.x, self.scrollView.frame.origin.y + 20, self.calendarWidth, self.scrollView.frame.size.height - self.weekLabel.frame.size.height * 3)];
} else {
[self.collectionView setFrame:CGRectMake(self.view.frame.origin.x, self.scrollView.frame.origin.y + 20, self.calendarWidth, self.scrollView.frame.size.height - self.weekLabel.frame.size.height * 7)];
}
[self.collectionView.collectionViewLayout invalidateLayout];
}
[Update] - Solved.
Thanks to #Adeel that the real problem is assigning the frame of my collectionview to the "frame" of the uiscrollview, instead the bug is solved after I set it to the "bounds" of the uiscrollview. But WHY is the UIScrollView's frame changed after getting any data ?
Related
Due to some purposes(like pull to refresh), I need a UICollectionView can bounce or scroll when there is no cells -- means numberOfItemsInSection: return 0
I have my code like this:
...
UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.minimumInteritemSpacing = SPLIT_SPACE;
flowLayout.minimumLineSpacing = SPLIT_SPACE;
targetCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - TABBAR_HEIGHT)
collectionViewLayout:flowLayout];
[targetCollection registerNib:[UINib nibWithNibName:#"DashboardCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:#"DashboardCell"];
targetCollection.autoresizingMask = UIViewAutoresizingFlexibleHeight;
targetCollection.backgroundColor = [UIColor colorWithHex:#"#EAEAEA"];
targetCollection.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
targetCollection.alwaysBounceVertical = YES;
...
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
{
return 0;
}
However, when testing, this empty UICollectionView cannot bounce nor scroll. I suspect it is related to empty cell, but I do need to enable the bounce or scroll when no cell.
This is similar to another of my problem:SVPullToRefresh cannot pull on an empty UICollectionView
Do it like this:
self.collectionView.alwaysBounceVertical = YES;
answer by #VNJ at here
Change this setting in your storyboard:
Swift Solution
collectionView.alwaysBounceVertical = true
You can try this:
collectionView.isScrollEnabled = false
- (void)_edgeInsetsToFit {
UIEdgeInsets edgeInsets = self.collectionView.contentInset;
CGSize contentSize = self.collectionView.contentSize;
CGSize size = self.collectionView.bounds.size;
CGFloat heightOffset = (contentSize.height + edgeInsets.top) - size.height;
if (heightOffset < 0) {
edgeInsets.bottom = size.height - (contentSize.height + edgeInsets.top) + 1;
self.collectionView.contentInset = edgeInsets;
} else {
edgeInsets.bottom = 0;
self.collectionView.contentInset = edgeInsets;
}
}
I called that method after layoutSubviews
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_STAssetViewController *weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf _edgeInsetsToFit];
});
}
You can try that way
I have a 100-row table and want to scroll it programmatically to any element and select that element. In first controller I specify row and section and push the controller with the UITableView onto navigation stack. In viewWillAppear of "tableView-controller" I use the code:
[tableView_ selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
The curious part is, it scrolls perfectly to any of 99 first rows, 100-th row gets selected, but remains "below" the visible area. I have to scroll the table manually to reveal it.
If I place that code in viewDidAppear, table scrolls nicely, but after a noticeable delay.
What did I also try:
Reducing the height of tableView. I got tableView which partly covers the screen with last row obscured indeed.
Playing with contentSize - setting its height to small large values - no luck.
Setting contentInset.bottom - worked, but I've got a useless space at the bottom.
In viewDidAppear, processing 99 rows as usual and setting custom contentOffset for the 100-th row:
offset.y += tableView_.contentSize.height - tableView_.bounds.size.height + 44;
worked too, but it seems to be an ugly way.
So, what should I do to get my tableView pre-scrolled even to 100-th element when "tableView-controller" appears?
UPDATE.
I do not use any xibs or storyboards, just defining views in viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
tableView_ = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tableView_.dataSource = self;
tableView_.delegate = self;
tableView_.sectionFooterHeight = 0.0f;
self.view = tableView_;
numbers = [NSMutableDictionary dictionary];
numberSectionTitles = [NSMutableArray array];
//... some model initialization
headerView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 320, 60}];
headerView.backgroundColor = [UIColor greenColor];
UILabel *l = [[UILabel alloc] initWithFrame:(CGRect){20, 20, 280, 20}];
l.textColor =[UIColor whiteColor];
l.tag = 121;
[headerView addSubview:l];
}
And adjust selection in viewDidAppear (dirty workarounds)
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
int row = _selectedIndex % 10;
int section = (_selectedIndex - row) / 10;
if(row == 9 && section == 9){
CGSize contentSize = tableView_.contentSize;
CGPoint offset = tableView_.contentOffset;
offset.y += tableView_.contentSize.height - tableView_.bounds.size.height + 44;
tableView_.contentOffset = offset;
}
[tableView_ selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
may be your view height is not same of tableview. your superview(on which you are adding your tableview) should be same. your last row is hiding because your view is not as same height as your tableview,may be this solve your problem.
You can do it manually:
[_tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:NO scrollPosition:UITableViewScrollPositionNone];
CGRect rect = [_tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
CGFloat offsetY = rect.origin.y+rect.size.height/2-_tableView.frame.size.height/2-_tableView.contentInset.top/2;
if (offsetY < -_tableView.contentInset.top)
offsetY = -_tableView.contentInset.top;
else if (offsetY > _tableView.contentSize.height-_tableView.frame.size.height)
offsetY = _tableView.contentSize.height-_tableView.frame.size.height;
_tableView.contentOffset = CGPointMake(_tableView.contentOffset.x, offsetY);
if (cell==nil)
if you've written an if statement like this in your CellforRowatIndexpath remove that particular if statement and proceed. That line causing problem
Enjoy coding
I am trying to create a grid of UIButtons . The row and column values are dynamic.I know how to create a grid .However making it using dynamic values is the problem.
-(void)makeLayoutWithMinRow:(int)minRow maxRow:(int)maxRow minColumn:(int)minColumn maxColumn:(int)maxColumn {
NSInteger intLeftMargin = 10; // horizontal offset from the edge of the screen
NSInteger intTopMargin = 10; // vertical offset from the edge of the screen
NSInteger intYSpacing = 30; // number of pixels between the button origins (vertically)
NSInteger intXTile;
NSInteger intYTile;
NSInteger width;
width = ((self.layoutView.frame.size.width-(maxColumn * 5))/maxColumn);
for (int y = minRow; y < maxRow; y++)
{
for (int x = minColumn; x < maxColumn; x++)
{
intXTile = (x * width) + intLeftMargin;
intYTile = (y * intYSpacing) + intTopMargin;
UIButton *buttons[x][y] = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
//Here I get error : Variable-sized object may not be initialised.
[self.layoutView addSubview:buttons[x][y]];
}
}
}
I did try the option as suggested by Cornelius below to store the button in array.
sButton = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
[buttons addObject:sButton];
How to add these buttons to view in this case?
for (UIButton *obj in buttons) {
[self.layoutView addSubview:obj]; //Doesn't work
}
Here is the one which replaces UICollectionView.I have tried
PSTCollectionView and it gives you the expected results. Try this.
You can use PSTCollectionView.
Use UICollectionView to create such grid.
Here is a tutorial. For your case, it's UIButton instead of UIImageView in this tutorial.
It seems all you're trying to achieve here is a lookup for the buttons later.
So you will need a variable (or property) on your instance to hold the references, not just a local variable during creation.
There are many ways of solving your problem, one simple yet efficient way to store the references is a 'NSMutableDictionary'.
Declare a property in your class:
#property (nonatomic, strong) NSMutableDictionary *buttonDictionary;
Set it up in your loop:
_buttonDictionary = [[NSMutableDictionary alloc] init];
In your loop, encode the x/y position, for example using an NSIndexPath, abusing row/section:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:y inSection:x];
Create button and add to your dictionary and superview:
UIButton *freshButton = [UIButton buttonWithType:...]; // Much better than initWithFrame
freshButton.frame = ...;
_buttonDictionary[indexPath] = freshButton;
[self.layoutView addSubview:freshButton];
If you want to look up a button later by x/y indices, just do
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:y inSection:x];
UIButton *requestedButton = _dictionary[indexPath];
Please note that I'm using the [] syntax on dictionaries here - you may use the classic methods objectForKey: and setObject:forKey: instead.
You can use UICollectionView and set the dynamic values as you desired or customized as per your requirement. This is very easy and effective way to develop grid view. Here I explained a simple code for grid view:
Like this :
#interface DashboardViewController : AbstractController <UICollectionViewDataSource, UICollectionViewDelegate>{
NSMutableArray *dataSource;
}
#property (nonatomic, strong) UICollectionView *dashboardCollectionView;
#property (nonatomic, strong) ModulesDataModel *modulesDataModel;
#end
/*****************.m********************/
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
_dashboardCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 135, 1024, 537) collectionViewLayout:layout];
[_dashboardCollectionView setDataSource:self];
[_dashboardCollectionView setDelegate:self];
[_dashboardCollectionView registerClass:[CellMaster class] forCellWithReuseIdentifier:#"Reuse"];
[_dashboardCollectionView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_dashboardCollectionView];
dataSource = [NSMutableArray arrayWithArray:#"your objects"];
}
#pragma mark - Collection View Datasource and Delegate Methods
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake( 22.0, 22.0, 22.0, 22.0);
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 22.0f;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 15.0f;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(312,150);
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return dataSource.count;
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Find the enum for this module and load the correct tile
self.modulesDataModel = [dataSource objectAtIndex:indexPath.item];
CellMaster * cell;
cell = (CellMaster *)[collectionView dequeueReusableCellWithReuseIdentifier:#"Reuse" forIndexPath:indexPath];
cell.tag = indexPath.item;
cell.iconImage.image = [UIImage imageNamed:#""];
cell.lblModuleName.text = self.modulesDataModel.moduleName;
cell.lblModuleName.textColor = self.modulesDataModel.color;
cell.btnInfo.tag = indexPath.item;
[cell.btnInfo addTarget:cell action:#selector(didPressInfoIcon:) forControlEvents:UIControlEventTouchUpInside];
cell.delegate = self;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// Enum for tile that was clicked
self.modulesDataModel = [dataSource objectAtIndex:indexPath.item];
}
Hope it would help you.
I made a little tweaks to your code and made it work with this:
You must manually initialize that array: meaning you have to say how big it's gonna be
#interface ViewController ()
#property (nonatomic) UIView *layoutView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.layoutView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.layoutView];
[self makeLayoutWithMinRow:0 maxRow:5 minColumn:0 maxColumn:5];
}
- (UIColor *)randomColor {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
return color;
}
-(void)makeLayoutWithMinRow:(int)minRow maxRow:(int)maxRow minColumn:(int)minColumn maxColumn:(int)maxColumn {
NSInteger intLeftMargin = 10; // horizontal offset from the edge of the screen
NSInteger intTopMargin = 10; // vertical offset from the edge of the screen
NSInteger intYSpacing = 30; // number of pixels between the button origins (vertically)
NSInteger intXTile;
NSInteger intYTile;
NSInteger width;
id buttons[maxRow][maxColumn];
width = ((self.layoutView.frame.size.width-(maxColumn * 5))/maxColumn);
for (int y = minRow; y < maxRow; y++)
{
for (int x = minColumn; x < maxColumn; x++)
{
intXTile = (x * width) + intLeftMargin;
intYTile = (y * intYSpacing) + intTopMargin;
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
button.backgroundColor = [self randomColor];
buttons[x][y] = button;
[self.layoutView addSubview:buttons[x][y]];
}
}
}
#end
You are trying to create a button-array or something like that here?
UIButton *buttons[x][y] = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
What you really want to do is create the button object and then add it to an array (if you want to access it afterwards, otherwise it's enough to add it as a subview):
// Outside the for loop, probably as an instance variable or property:
NSMutableArray *buttons = [[NSMutableArray alloc] init];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, width, 15)];
[buttons addObject:button];
You may even need to put that buttons array inside another array to get the multidimensional aspect right, or use a NSMutableDictionary with corresponding keys.
Im trying to refactor my code for better memory management and performance. I have an array of 12 images, but I want to load them as needed, not all at the same time. So maybe the current image -1, the current image and the current image +1. I viewed some of the answers on SO but found them unclear. I felt it would be clearer if I posted my code for reference.
//scroll view set up
- (void)scrollViewSetUp
{
self.scrollview.delegate = self;
for (int i = 0; i < _images.count; i++)
{
CGRect frame;
frame.origin.x = self.scrollview.frame.size.width * i;
frame.size = self.scrollview.frame.size;
self.scrollview.pagingEnabled = YES;
UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [UIImage imageNamed:[_images objectAtIndex:i]];
[self.scrollview addSubview:subview];
}
self.scrollview.contentSize = CGSizeMake(self.scrollview.frame.size.width * _images.count, self.scrollview.frame.size.height);
self.automaticallyAdjustsScrollViewInsets = NO;
//page control ie .... at bottom of
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(100.0,0.0,100.0,40.0)];
[self.pageControl setNumberOfPages:_images.count];
[self.pageControl setCurrentPage:0];
self.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
self.pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
[self.pageControl setBackgroundColor:[UIColor clearColor]];
[self.viewForPageControl addSubview:self.pageControl];
[self.viewForPageControl setBackgroundColor:[UIColor clearColor]];
}
#pragma mark - UIScrollView Delegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
int newOffset = scrollView.contentOffset.x;
int newPage = (int)(newOffset/(scrollView.frame.size.width));
[_pageControl setCurrentPage:newPage];
}
Any advice or direction is greatly appreciated.
As per Gman's request I reposted my comment.
This tutorial will help you:
http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
You could try to reuse your UIImageView as they go offscreen... but you'll be just trying to redo what UITableview already does. UITableView with a custom UITableViewCell would take care of notifying you when new cells comes visible and dequeuing the ones that are offscreen.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"yourCustomImageCell";
//look if there are cells that could be reused
CustomImageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) { //if not, create a new one
cell = [[CustomImageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
//Set your image here
return cell;
}
Not sure if this is the best way of doing it, but it's an option.
You can set the tag property on your UIImageView to correspond to your index in your loop when setting the scrollView.
Then in your scrollViewDidEndDecelerating method:
for (int i = 0; i < _salonImages.count; i++)
{
if(i == (newPage-1))
{
UIImageView *imgView = (UIImageView*)[self.scrollView viewWithTag:newPage-1];
imgView.image = [_images objectAtIndex:newPage-1];
}
else if(i == newPage)
{
UIImageView *imgView = (UIImageView*)[self.scrollView viewWithTag:newPage];
imgView.image = [_images objectAtIndex:newPage];
}
else if(i == (newPage + 1 ))
{
UIImageView *imgView = (UIImageView*)[self.scrollView viewWithTag:newPage+1];
imgView.image = [_images objectAtIndex:newPage+1];
}
else
{
UIImageView *imgView = (UIImageView*)[self.scrollView viewWithTag:i];
imgView.image = nil;
}
}
I am having some strange uitableview behavior- my customs cells have a little extra space around them that I cannot fix. I can also move the cells in that space. I have attached a couple of pictures as my English is not letting me to explain better. Any ideas on what might the issue be? I can post my code for my custom cell but it even happens with admob add cell, so I am not sure it is related to the custom cell.
EDIT: Added code for heights
EDIT2: I changed the scroll view alloc to
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width,self.bounds.size.height)];
And it fixed the moving of the cell. But that white line is still there.
Table View
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// return (self.tableViewHome.bounds.size.height-49-6-self.tableViewHome.tableHeaderView.bounds.size.height-self.tableViewHome.tableFooterView.bounds.size.height-GAD_SIZE_320x50.height)/3;
float height = self.tableViewHome.frame.size.height-self.tableViewHome.tableHeaderView.bounds.size.height-30.0;
if (indexPath.item==5)
{
height=kGADAdSizeBanner.size.height;
}
else
{
if (indexPath.item==1 || indexPath.item==3)
{
height=15.0;
}
else
{
if (indexPath.item==0 || indexPath.item==2 || indexPath.item==4)
{
height=(height-kGADAdSizeBanner.size.height)/3;
}
}
}
NSLog(#"Height:%f",height);
return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
Custom Cell
-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[scrollView setShowsHorizontalScrollIndicator:NO];
[scrollView setShowsVerticalScrollIndicator:NO];
// NSInteger viewcount= 3;
// for(int i = 0; i< viewcount; i++) {
// CGFloat x = 2 * self.bounds.size.width;
todayView = [HomeTodayView homeTodayView];
todayView.frame = CGRectMake(0, 0,self.bounds.size.width, self.bounds.size.height);
todayView.backgroundColor = [UIColor redColor];
avgView = [HomeAvgView homeAvgView];
avgView.frame = CGRectMake(self.bounds.size.width, 0, self.bounds.size.width, self.bounds.size.height);
// [[HomeTodayView alloc] initWithFrame:
todayView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
avgView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[scrollView addSubview:todayView];
[scrollView addSubview:avgView];
scrollView.contentSize = CGSizeMake(self.bounds.size.width *2, self.bounds.size.height+100);
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
[self addSubview:scrollView];
}
return self;
}
Try This:
[table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
NOTE:- table = your tableview name.
If this does not work then please check that your custom cell height and the row height of tableView are same?