Adjusting the height of a uitableview section footer - ios

I am just starting to use a UITableView section footer, but am having some problems. So I have a UITableView with an edit button attached to the bottom using a footer. My first problem is that when you click on that button, the footer should double in size because the edit button then becomes an add button and a done button, instead of just one button. What would be the best way to make the size of the footer bigger. I have tried changing the frame of the footer through self.tableView.tableFooterView.frame = CGRectMake(0, 0, 320, 88); but this does not work.
My second problem is that I would like the footer to always scroll with the table, like it is just another cell. It should just be located at the bottom of the table no matter what. If the user scrolls down, it should not stop at the bottom of the screen and stick, it should just keep scrolling with the rest of tableview. How would I fix this?
Here is how I am creating the footer:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 48;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
//view.backgroundColor = [UIColor grayColor];
self.addButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.addButton.frame = CGRectMake(0, 0, 320, 44);
[self.addButton setImage:[UIImage imageNamed:#"Add_Class_Button"] forState:UIControlStateNormal];
[self.addButton setImage:[UIImage imageNamed:#"Add_Class_Button"] forState:UIControlStateHighlighted];
[self.addButton addTarget:self action:#selector(addSelected:) forControlEvents:UIControlEventTouchUpInside];
self.addButton.hidden = YES;
[view addSubview:self.addButton];
self.editButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.editButton.frame = CGRectMake(0, 0, 320, 44);
[self.editButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateNormal];
[self.editButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateHighlighted];
[self.editButton addTarget:self action:#selector(editSelected:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:self.editButton];
self.editDoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.editDoneButton.frame = CGRectMake(0, self.addClassButton.frame.size.height-2, 320, 44);
[self.editDoneButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateNormal];
[self.editDoneButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateHighlighted];
[self.editDoneButton addTarget:self action:#selector(doneSelected) forControlEvents:UIControlEventTouchUpInside];
self.editDoneButton.hidden = YES;
[view addSubview:self.editDoneButton];
self.editLabel = [[UILabel alloc] init];
self.editLabel.frame = CGRectMake(10, 5, 100, 30);
self.editLabel.text = #"Edit";
self.editLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:17];
[view addSubview:self.editLabel];
self.addLabel = [[UILabel alloc] init];
self.addLabel.frame = CGRectMake(10, 5, 100, 30);
self.addLabel.text = #"Add";
self.addLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:17];
self.addLabel.hidden = YES;
[view addSubview:self.addLabel];
self.editDoneLabel = [[UILabel alloc] init];
self.editDoneLabel.frame = CGRectMake(10, self.addClassButton.frame.size.height + 5, 150, 30);
self.editDoneLabel.text = #"Done";
self.editDoneLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:17];
self.editDoneLabel.hidden = YES;
[view addSubview:self.editDoneLabel];
self.theLine = [[UIView alloc] init];
self.theLine.frame = CGRectMake(0, 0, 320, .5);
UIColor *borderColor = [UIColor colorWithRed:193/255.5 green:193/255.0 blue:193/255.0 alpha:1.0];
self.theLine.backgroundColor = borderColor;
[view addSubview:self.theLine];
return view;
}
Edit
After the taking into account the answers bellow, this is what I have switched to, but now where my footer used to be, there is just a grey rectangle.
Here is the code that I am now using:
-(void)setUpFooter {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 48)];
view.backgroundColor = [UIColor redColor];
self.addButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.addButton.frame = CGRectMake(0, 0, 320, 44);
[self.addButton setImage:[UIImage imageNamed:#"Add_Class_Button"] forState:UIControlStateNormal];
[self.addButton setImage:[UIImage imageNamed:#"Add_Class_Button"] forState:UIControlStateHighlighted];
[self.addButton addTarget:self action:#selector(addSelected:) forControlEvents:UIControlEventTouchUpInside];
self.addButton.hidden = YES;
[view addSubview:self.addButton];
self.editButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.editButton.frame = CGRectMake(0, 0, 320, 44);
[self.editButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateNormal];
[self.editButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateHighlighted];
[self.editButton addTarget:self action:#selector(editSelected:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:self.editButton];
self.editDoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.editDoneButton.frame = CGRectMake(0, self.addClassButton.frame.size.height-2, 320, 44);
[self.editDoneButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateNormal];
[self.editDoneButton setImage:[UIImage imageNamed:#"Edit_Classes_Button"] forState:UIControlStateHighlighted];
[self.editDoneButton addTarget:self action:#selector(doneSelected) forControlEvents:UIControlEventTouchUpInside];
self.editDoneButton.hidden = YES;
[view addSubview:self.editDoneButton];
self.editLabel = [[UILabel alloc] init];
self.editLabel.frame = CGRectMake(10, 5, 100, 30);
self.editLabel.text = #"Edit";
self.editLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:17];
[view addSubview:self.editLabel];
self.addLabel = [[UILabel alloc] init];
self.addLabel.frame = CGRectMake(10, 5, 100, 30);
self.addLabel.text = #"Add";
self.addLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:17];
self.addLabel.hidden = YES;
[view addSubview:self.addLabel];
self.editDoneLabel = [[UILabel alloc] init];
self.editDoneLabel.frame = CGRectMake(10, self.addClassButton.frame.size.height + 5, 150, 30);
self.editDoneLabel.text = #"Done";
self.editDoneLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:17];
self.editDoneLabel.hidden = YES;
[view addSubview:self.editDoneLabel];
self.theLine = [[UIView alloc] init];
self.theLine.frame = CGRectMake(0, 0, 320, .5);
UIColor *borderColor = [UIColor colorWithRed:193/255.5 green:193/255.0 blue:193/255.0 alpha:1.0];
self.theLine.backgroundColor = borderColor;
[view addSubview:self.theLine];
view.userInteractionEnabled = YES;
self.classTableView.tableFooterView = view;
self.classTableView.tableFooterView.userInteractionEnabled = YES;
}

hope I can help.
To set the section footer height you also have to change the returned value in the method heightForFooterInSection. To reload the height you can call [tableView reloadData] or [tableView reloadSections:...].
A table section footer always stick to the bottom of the screen but there is a different view used to place things after the table view.
The tableView.tableFooterView is a view that is located after the table view. Change this to add elements after the table view.
Cheers!

There are two types of footers in a UITableView. There is the table footer at the bottom of the table, and there is the table section footer at the bottom of each section.
It sounds like you want to use table section headers. However, your code snippet is setting the frame of the table footer, not the table section footers.
self.tableView.tableFooterView.frame = CGRectMake(0, 0, 320, 88);
If you want to adjust the table section footer height, the tableView:heightForFooterInSection: method will need to return a different value.

Related

viewForFooterInSection not showing into the bottom of the screen

viewForFooterInSection not showing into the bottom of the screen(uitableview).
here I am using UItableview.
Note: in below screen vary bottom of the screen one more footer added.(white color view).
Redcolorview: footer (from below code)
blue color: table background color
white bottom:
Red color view I added programmatically, using below code:
- (CGFloat)tableView:(UITableView *)tableView
estimatedHeightForFooterInSection:(NSInteger)section
{
return 44;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
NSLog(#"%f",tableView.frame.size.width);
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 44)];
view.backgroundColor = [UIColor redColor];
UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 7, tableView.frame.size.width/2 - 60, 30)];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cancelButton setBackgroundColor:[ValidationsClass colorWithHexString:NSLocalizedStringFromTableInBundle(#"pothysapp_label_text_backgroundcolor",#"ApplicationSettings",[NSBundle mainBundle], nil)]];
[cancelButton addTarget:self
action:#selector(cancelDetails:)
forControlEvents:UIControlEventTouchUpInside];
cancelButton.titleLabel.font = [UIFont fontWithName:#"Roboto-Bold" size:15];
cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[view addSubview:cancelButton];
UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(tableView.frame.size.width/2 + 30, 7, tableView.frame.size.width/2 - 60, 30)];
[saveButton setTitle:#"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[saveButton setBackgroundColor:[ValidationsClass colorWithHexString:NSLocalizedStringFromTableInBundle(#"pothysapp_label_text_backgroundcolor",#"ApplicationSettings",[NSBundle mainBundle], nil)]];
[saveButton addTarget:self
action:#selector(saveDetails:)
forControlEvents:UIControlEventTouchUpInside];
saveButton.titleLabel.font = [UIFont fontWithName:#"Roboto-Bold" size:15];
saveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[view addSubview:saveButton];
return view;
}
Try this instead of returning your custom view in viewForFooterInSection.
Add your custom view to table footer in ViewdidLoad()
self.tableview.tableFooterView =//Your CustomView;
I removed estimatedHeightForFooterInSection and viewForFooterInSection.
Instead of this i added view in viewdidload:
self.tableview.contentInset = UIEdgeInsetsMake(0, 0, -20, 0);
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 15, self.view.frame.size.width, 30)];
view.backgroundColor = [UIColor whiteColor];
self.tableview.tableFooterView = view;
UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 7, self.view.frame.size.width/2 - 60, 30)];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[view addSubview:cancelButton];
UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2 + 30, 7, self.view.frame.size.width/2 - 60, 30)];
[saveButton setTitle:#"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[view addSubview:saveButton];

UIButton Selector method not working

I am creating a UIIimageView programtically than I create the UIView and in uiview I added two uibutton programtically but button selector method not working . I tried many thing but nothing happened . Here is my code
-(void) pagingFunc{
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
CGFloat height = CGRectGetHeight(screen);
//ScrollView Size and Contents
CGSize mxSize = CGSizeMake( [imgesArry count]*width , height-114);
[scrlView setContentSize : mxSize];
self.customView.translatesAutoresizingMaskIntoConstraints =YES;
self.customView.frame = CGRectMake(0, 0, mxSize.width, mxSize.height);
int incX = 0 ;
for( int i = 0; i < [imgesArry count]; i++)
{
PFObject *imageObject = [imgesArry objectAtIndex:i];
PFFile *file;
if (height == 480) {
file = [imageObject objectForKey:#"image4s"];
}
else{
file = [imageObject objectForKey:#"image6s"];
}
NSString * imgFile = [file url];
UIImageView* imagView = [[UIImageView alloc]initWithFrame : CGRectMake(incX,0,width ,height)];
imgView.userInteractionEnabled = YES;
[imagView sd_setImageWithURL:[NSURL URLWithString:imgFile] placeholderImage:[UIImage imageNamed:#"UserUpdationImageCell.png"]];
btnView = [[UIView alloc] initWithFrame:CGRectMake(incX, imagView.frame.size.height-60, width, 50)];
btnView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.8];
UIButton *bckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[bckBtn addTarget:self
action:#selector(aMethod)
forControlEvents:UIControlEventTouchUpInside];
[bckBtn setTitle:#"Back" forState:UIControlStateNormal];
bckBtn.frame = CGRectMake(0 ,0, 160.0, 40.0);
UIButton *downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[downloadBtn addTarget:self
action:#selector(aMethod)
forControlEvents:UIControlEventTouchUpInside];
[downloadBtn setTitle:#"Download" forState:UIControlStateNormal];
downloadBtn.frame = CGRectMake(160 ,0, 160.0, 40.0);
[btnView addSubview:bckBtn];
[btnView addSubview:downloadBtn];
[self.customView addSubview:imagView];
[self.customView addSubview:btnView];
incX+= width;
}
[scrlView setContentOffset:CGPointMake(width*selectedIndex, 0)];
}
May be you can set : self.customView.userInteractionEnabled=YES;
I write a simple demo you describe and it works:
// imagView -> view1 -> bckBtn
UIImageView *imagView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
imagView.userInteractionEnabled = YES;
imagView.backgroundColor = [UIColor grayColor];
[self.view addSubview:imagView];
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
view1.backgroundColor = [UIColor yellowColor];
[imagView addSubview:view1];
UIButton *bckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
bckBtn.frame = CGRectMake(10, 10, 50, 50);
bckBtn.backgroundColor = [UIColor redColor];
[bckBtn addTarget:self
action:#selector(aMethod)
forControlEvents:UIControlEventTouchUpInside];
[bckBtn setTitle:#"Back" forState:UIControlStateNormal];
[view1 addSubview:bckBtn];
-(void)aMethod{
NSLog(#"button click");
}
Hope it helps.
Well 1st thing, make sure you don't have any overlays over buttons.
Also you might try using GestureRecognizers.
Here's a Swift snippet, I'm pretty sure it can be translated to obj-c
let xButton = UIButton(frame: CGRect(x: 0, y: 0, width: 160, height: 40))
xButton.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(aMethod)))

How to fix a button at the bottom of the tableview?

In my App i want to fix a button at the bottom of the table view.
Here is my Initial Screen,
Button created at the footer section
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(tableView == educateTbl)
{
float footerWidth = 150.0f;
float padding = 10.0f;
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, footerWidth, 50.0)];
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *addEdu = [[UIButton alloc]initWithFrame:CGRectMake(padding, 0, footerWidth - 2.0f * padding, 44.0f)];
addEdu.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
addEdu.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[addEdu setTitle:#"Add Education" forState:UIControlStateNormal];
[addEdu addTarget:self action:#selector(addEducation:) forControlEvents:UIControlEventTouchUpInside];
[addEdu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
addEdu.frame=CGRectMake(0, 0, 200, 30);
[footerView addSubview:addEdu];
return footerView;
}
return nil;
}
After that i am getting like this,
How can i fix that?
why you dont make something like this?
-(void)setTableFooter
{
float footerWidth = 150.0f;
float padding = 10.0f;
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, footerWidth, 50.0)];
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *addEdu = [[UIButton alloc]initWithFrame:CGRectMake(padding, 0, footerWidth - 2.0f * padding, 44.0f)];
addEdu.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
addEdu.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[addEdu setTitle:#"Add Education" forState:UIControlStateNormal];
[addEdu addTarget:self action:#selector(addEducation:) forControlEvents:UIControlEventTouchUpInside];
[addEdu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
addEdu.frame=CGRectMake(0, 0, 200, 30);
[footerView addSubview:addEdu];
tableView.tableFooterView = footerView;
}
and call this after you init the table
If you want section footer/header scroll with tableview, you need to use a grouped style table view.
[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped]
And a grouped style table view will have a default backgroundColor and section header/footer height. You need set these value explicitly.
If you have only one section, it is better to use tableFooterView instead of section footer view
While Scrolling that button visible means ,UITableview cell are reusable so that button is available ,what you have to do means .
1.Take number of row in UITableView ,
Then inside cell for row at indexpath :
Total number of row ==indexpath.row
{
//inside this button.hidden=no;
}
else
{
//button.hidden=yes;
}
-(void)CreateCustomFooter
{
float footerWidth = 150.0f;
float padding = 10.0f;
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, footerWidth, 50.0)];
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *addEdu = [[UIButton alloc]initWithFrame:CGRectMake(padding, 0, footerWidth - 2.0f * padding, 44.0f)];
addEdu.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
addEdu.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[addEdu setTitle:#"Add Education" forState:UIControlStateNormal];
[addEdu addTarget:self action:#selector(addEducation:) forControlEvents:UIControlEventTouchUpInside];
[addEdu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
addEdu.frame=CGRectMake(0, 0, 200, 30);
[footerView addSubview:addEdu];
tableView.tableFooterView = footerView;
}
Put above method in viewDidLoad() Method and after initializing tableview

custom UITableViewCell doesn't show data before showing full cell when scrolling

My application has custom UITableViewCell with large height 470px.
I created custom cell with fully programatically.
This is my cellForRowAtIndexPath method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
pixDealsTableViewCell *dealCell = (pixDealsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:#"Deals" forIndexPath:indexPath];
if (dealCell == nil) {
dealCell = [[pixDealsTableViewCell alloc] init];
}
dealCell.dBusinessLogo.image = [pixUtil imageWithImage:[UIImage imageNamed:#"profile_icon"] scaledToSize:CGSizeMake(60, 60)];
[dealCell.dBusinessName setTitle:#"Business Name" forState:UIControlStateNormal];
dealCell.dTimeAgo.text = [NSString stringWithFormat:#"5 min ago"];
[dealCell.dHeading setTitle:#"Deals Head" forState:UIControlStateNormal];
[dealCell.dDescription setTitle:#"Descriptionskjdfnkjsdnfis" forState:UIControlStateNormal];
dealCell.dImage.image = [pixUtil imageWithImage:[UIImage imageNamed:#"carrier.png"] scaledToSize:CGSizeMake(290, 250)];
[dealCell.dLike setTitle:#"Like" forState:UIControlStateNormal];
[dealCell.dShare setTitle:#"Share" forState:UIControlStateNormal];
return dealCell;
}
This is my custom cell init method
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
NSLog(#"NEW CELL");
customRed = [[UIColor alloc]initWithRed:209.0f/255.0f green:19.0f/255.0f blue:38.0f/255.0f alpha:1.0f];
[self setBackgroundColor:[UIColor grayColor]];
containerCell = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 700)];
[containerCell setBackgroundColor:[UIColor whiteColor]];
self.dBusinessLogo = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 60, 60)];
self.dBusinessName = [[UIButton alloc]initWithFrame:CGRectMake(80, 20, 225, 20)];
[self.dBusinessName setTitle:#"Business Name" forState:UIControlStateNormal];
self.dBusinessName.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dBusinessName addTarget:self action:#selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dBusinessName setTitleColor:customRed forState:UIControlStateNormal];
self.dTimeAgo = [[UILabel alloc]initWithFrame:CGRectMake(80, 50, 225, 15)];
self.dHeading = [[UIButton alloc]initWithFrame:CGRectMake(15, 80, 290, 20)];
self.dHeading.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dHeading addTarget:self action:#selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dHeading setTitleColor:customRed forState:UIControlStateNormal];
self.dDescription = [[UIButton alloc]initWithFrame:CGRectMake(15, 105, 290, 50)];
self.dDescription.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dDescription addTarget:self action:#selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dDescription setTitleColor:customRed forState:UIControlStateNormal];
self.dImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 160, 290, 250)];
self.dLike = [[UIButton alloc]initWithFrame:CGRectMake(10, 420, 150, 40)];
self.dLike.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dLike addTarget:self action:#selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dLike setTitleColor:customRed forState:UIControlStateNormal];
self.dShare = [[UIButton alloc]initWithFrame:CGRectMake(160, 420, 150, 40)];
self.dShare.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[self.dShare addTarget:self action:#selector(haveAccount:) forControlEvents:UIControlEventTouchUpInside];
[self.dShare setTitleColor:customRed forState:UIControlStateNormal];
[self.contentView addSubview:containerCell];
[self.contentView addSubview:self.dBusinessLogo];
[self.contentView addSubview:self.dBusinessName];
[self.contentView addSubview:self.dTimeAgo];
[self.contentView addSubview:self.dHeading];
[self.contentView addSubview:self.dDescription];
[self.contentView addSubview:self.dImage];
[self.contentView addSubview:self.dShare];
// NSLog(#"Deals View added");
}
return self;
}
This is my UITableViewCell fully viewed.
When I scroll down to next cell, It doesn't load properly.
It loads correctly after fully scrolled the cell to up
Please Help me to solve this problem.
Finally I got answer. I created containerCell view with height of 700. But cell height is 470 only.
I changed that containerCell view height to 470. Its fixed my problem. :)

add subView to another SubView ios

i am trying to show comments list by using subview. I added subview to self.view, and i added a tableview to it in order to show comments list. now i want to enable user to add comment, i tried to add another subview to the first one with text field and button, but the view shown up and the text field and button do not. this is the code i use to do so:
GRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
// notification button
myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight )];
[myView setBackgroundColor:[UIColor whiteColor]];
commentView = [[UIView alloc] initWithFrame:CGRectMake(0,screenHeight-70,screenWidth,70)];
[commentView setBackgroundColor:[UIColor redColor]];
table = [[UITableView alloc] initWithFrame:CGRectMake(0,50, screenWidth, screenHeight-100)];;
table.dataSource=self;
table.delegate=self;
UILabel *currentdate = [[UILabel alloc] initWithFrame:CGRectMake(0,10,screenWidth-40,50)];
currentdate.backgroundColor = [UIColor clearColor];
[currentdate setTextColor: [UIColor blueColor]];
[currentdate setText:#"Comments"];
currentdate.textAlignment= UITextAlignmentCenter;
currentdate.font = [UIFont fontWithName:#"Helvetica" size:20.0];
commentFeild = [[UITextField alloc] initWithFrame:CGRectMake(50,screenHeight-50,screenWidth-50,50)];
commentFeild.placeholder=#"add comment";
commentFeild.backgroundColor = [UIColor whiteColor];
[commentFeild setTextColor: [UIColor blueColor]];
commentFeild.textAlignment= UITextAlignmentRight;
commentFeild.font = [UIFont fontWithName:#"Helvetica" size:15.0];
[commentFeild.layer setCornerRadius:14.0f];
[commentFeild setTag:2030];
//[commentFeild setDelegate:self];
UIButton *doneBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
doneBtn.frame = CGRectMake(screenWidth-45, 10,40, 30);
doneBtn.backgroundColor = [ UIColor clearColor];
[doneBtn setTitle:#"Done" forState:UIControlStateNormal];
[doneBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[doneBtn addTarget:self action:#selector(hide) forControlEvents:UIControlEventTouchUpInside];
UIButton *add=[UIButton buttonWithType:UIButtonTypeRoundedRect];
add.frame = CGRectMake(0,screenHeight-50,40,50);
add.backgroundColor = [ UIColor clearColor];
[add setTitle:#"add" forState:UIControlStateNormal];
[add setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[add addTarget:self action:#selector(addComment) forControlEvents:UIControlEventTouchUpInside];
if(![taskObject.status isEqualToString:#"doneTask"])
{
[commentView addSubview:commentFeild];
[commentView addSubview:add];
}
[myView addSubview:doneBtn];
[myView addSubview:currentdate];
[myView addSubview:table];
[myView addSubview:commentView];
[self.view addSubview:myView];
You are adding commentFeild in commentView.
commentView = [[UIView alloc] initWithFrame:CGRectMake(0,screenHeight-70,screenWidth,70)];
Height of commentView is 70 and y position of commentField is screenHeight-50 this y position is to large as compare to commentView height.
x and y position of child view is calculated from parents x and y.
The frame of the commentField is causing the problem as the y value is very large the comment textfield is not displayed in the commentview
Correct the frame and it will show up
commentFeild = [[UITextField alloc] initWithFrame:CGRectMake(50,0,screenWidth-50,50)];
note :frame of a view is depending only to its parent view not any supers of the parent,In your case commentField's frame depends on comment view dimensions and nothing to do with any other superview

Resources