How set the background Image for a section in UITableview? - uitableview

Hav a option to set background image or color to cell.
How can I suppose to do that for a section with number of rows and each row in the section will be in different color..

You can do the same by using delegate method of UITableView,
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
In this method, you can set individual UIView according to section. Moreover, you can set individual section's height by overriding...
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

Related

What are default methods that gets called when we scroll tableView iOS

In my tableViewCell, I am trying to display dynamic content from CoreData string object in a textView with a background image. When the tableView is loading for the first Time, background image is stretching to right and text content in textView is trimming, but when I scroll the tableView, rect of background image is appearing as expected however, textView content is still trimming. can anyone please tell me what default methods will system call internally when we scroll a tableView? Because some method is setting my background Image rect correctly which i am failing to set in initial loading of tableView.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Many more please check tableview data delegate and data source Methods.

Disable part of Cell in UITableView

I am trying to disable part of the UITableView cell. Please see image below.
This white part is a view in my cell. I don't know how to disable it, so that when user taps it nothing will happen. Maybe some king of mask?
Moving this out of the comments section. If you want padding between your cells what you should do is make each row its own section and use the delegate method
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section
However, this method will not be called if your tableview is the default style. So, set your tableview style to UITableViewStyleGrouped
Then you have to implement the delegate methods so that you return a height for the footer and make sure that each row gets its own section:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//Return however many rows you have specifically or the count of the datasource
return [array count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
CGFloat myHeight = 50.0 //your height here
return myHeight;
}
Implementing these three delegate methods like this should add a nice transparent padding between your cells.
Try this simple approach.Place a button on top of custom table view cell to mask the area which you want to be un-clickable. This acts as a mask on top of tableview cell which stops calling row did select delegate method. If you want to add any action for button click event add a method to button by passing row index.

Remove space at the top of first row in table view

In my application i'm using custom cell in table view to display images in all rows. But in my .xib file there is a big empty space comes at the top of the custom cell. Can anyone tell me that how remove that space in iOS7 (iPad)? (like how to change the Y axis of the custom cell)
This is an IOS7 related issue with UITableViewStyleGrouped and size of footer views in section.
If you set the footerView to be size 0 it defaults to a larger value, The solution I found was to set the footer to a very small non zero number
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.0000001f;
}
Try to set into your property inspector like this..
This might help you:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectNull];
sectionHeader.hidden = YES;
return sectionHeader;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0;
}
Sometimes the empty space in the first row is the section header space. This functions eliminate it.

Set row height of a UITableView according to the cell in that row

I want to adjust the row height of a UITableView according to the cell in that row.
Initially, I tried to use
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
However, the problem is, when the table is loading, the calling flow is seemed to be:
First call:
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Then call:
(UIViewTableCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
which means, before my cell is generated, I have to tell the table the height of its row.
However, what I want is exactly the opposite, i.e., after my cell is generated, I tell the table the height of this rows.
Is there any method to achieve this?
Make an array of heights for every row based on the data from tableView: cellForRowAtIndexPath: and in the tableView heightForRowAtIndexPath: just take the height value from that array.
Declare in your implementation file:
NSMutableArray *heights;
In viewDidLoad: initialise it:
heights = [NSMutableArray array];
In tableView: cellForRowAtIndexPath: set the height for each row:
[heights addObject:[NSNumber numberWithFloat:HEIGHT]];
And in the tableView heightForRowAtIndexPath: return required height:
return [heights objectAtIndex:indexPath.row];
This should work because tableView: cellForRowAtIndexPath: is called for every cell and then for every cell tableView heightForRowAtIndexPath: is called.
may be the only solution is make a variable into the .h file like
#property (nonatomic) int height
initialise it into the viewDidLoad like
self.height = 40;
and then return this variable into the
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return self.height;
}
then in your tableView: cellForRowAtIndexPath: update this variable like your new height and then reload the [self.yourTable reloadData] in your viewDidAppear

How to set color in empty UITableViewCell?

I want to replicate Gowalla UI of the detail part (the table with Map & Directions) picture below
I replicate it with a table with a contentInset, set backgroundColor to clearColor, and change color of UITableViewCell in - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath to white, but the result
isn't what I expected the empty cells are white only the cells with content (a number return by - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section ) here is a result I got
Is there any way to set empty cell color or any guide on how to achieve this ?
Set background color of view same as you are setting for your cell. and make cell transparent.
Due to no response for long time I would posted my solution here. I solved this problem by having UITableView under UIView and set parent view background color the same as UITableViewCell color.

Resources