How to hide the headers of my UITableViews sections programmatically? - ios

I want the headers and footers for my UITableView's sections to be hidden, and I'm currently setting them up like so:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return nil;
}
As you can see in the screenshot, this has successfully hidden the footers, but not the headers (shown in gray). What's missing?

Method heightForHeaderInSection doesn't work with 0. Try this one:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.0001f;
}

Related

How to dynamic cell height with Parse?

Here is my storyboard:
The method i use to get the image is:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
cell.mainImage.file = (PFFile *)object[#"image"];
[cell.mainImage loadInBackground];
}
Row Height is set as:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 501.0f;
}
I also would like to have the Image to be filled perfectly, much like instagram. I dont want images to have bars on the top and bottom.
this was work for me
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}

How to expand my table view cell?

Using this code to expand the table view cell,but its not working for me.I know there is some thing wrong in this code help me to find out.
![selectindex = -1;
// Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return \[Arr_lbl count\];
}
#pragma mark table cell creating and loading the data
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AntzclubCell *cell=\[tableView dequeueReusableCellWithIdentifier:#"Antz"\];
cell.img_antzClub.image=\[UIImage imageNamed:\[Arr_img objectAtIndex:indexPath.row\]\];
cell.lbl_antzClub.text=\[Arr_lbl objectAtIndex:indexPath.row\];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor=\[UIColor blackColor\];
return cell;
}
#pragma mark expanding height
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectindex==indexPath.row){
return 400;
}
else{
return 132;
}
}
#pragma mark user selecting option
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==selectindex) {
selectindex=-1;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
return;
}
if(selectindex !=-1)
{
NSIndexPath *prepath=\[NSIndexPath indexPathForRow:selectindex inSection:0\];
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:prepath\] withRowAnimation:UITableViewRowAnimationLeft\];
}
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
}]
this image is my output while i click the cell its merged with other data not expanding.
Depending on the versions of iOS you want to support the answer may differ, but it seems you didn't implement heightForRowAtIndexPath:

Remove text of uitableviewcell when you are delegating two uitableview

I have a uitableviewdelegate class that is delegate of two uitableview. I want that one of them has remove button and the other do not have remove button. I used below code:
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView==self.firstTableView){
return #"Remove";
}else
return #"";
}
button my code do not disable editing style for secondTableView it just set empty text as title. How can I do this?
EDIT
I also use below methods:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == slef.FirstTableView){
//Some codes
}
}
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == self.FirstTableView){
//Some codes
}
}
but any of them was not helpful.
Please implement this delegate method.
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView==self.firstTableView) {
return NO;
}
return YES;
}
Use delegate method
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
Here you can return UITableViewCellEditingStyleNone or UITableViewCellEditingStyleDelete for desired table

iOS overlay a header cell over another cell in a UITableView

I have a custom header bar in my UITableView that I want to overlap the cell below it. Does anyone know if this is possible? At the moment I've tried off setting the scroll up but doesn't seem to work does anyone have any ideas?
Here's what I have tried
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) return 200;
else return 100;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return #"";
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
headerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"hm_pullToRefreshBar.png"]];
return headerView;
}
EDIT: I've tried to make the header height 10 pixels shorter than the UIView that I've set for the header view, but that just cuts the graphic off instead of letting it overlap.

How to manually set UITableViewCell?

I created UITableVewCell subclass for my cell and I want set height of cell to 70px. It's possible? How can I do that?
I found solution;
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 70;
}
You need to use the Delegate method of UITableView,similarly there are lot's of method for other purpose too.
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 70;
}
For more details follow the below link:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006942-CH3-DontLinkElementID_3

Resources