From the docs:
A plain-style table view is an unbroken list; a grouped table view has visually distinct sections.
So in plain style, I can't have any sections? Or if I had some, they could not be visually distinct? Is that right?
A plain style table view can have sections, but they are divided only by a thin blue heading with the section name. If you look at this image you can compare the different styles. The left image is a plain table view without sections and the middle image is a plain view with sections. The 'A' heading denotes a section called A.
'Plain' can indeed have sections; the address book is a good example.
I'm not at my development machine, so can't grab a code example this minute. The mechanism to achieve this can differ depending on your method of providing data to your UITableView.
Will post examples later if no one else beats me to it.
EDIT: I can't add a comment to Matt's answer, so will add it here.
The thin blue line is the default implementation, you can provide your own custom views using the delegate:
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Yups, definitely they can have sections and the sections are separated by headers. For refernce please see the contacts application in iPhone device/simulator with some contacts added.
A plain-style table view is an unbroken list; a grouped table view has visually distinct sections.
This line means in the grouped style table the sections are separated by some blank space but not in plain style tables
Yes , A plain tableview can have section
You need to implement mmethods :
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
iOS UITableView styles(Plain, Grouped, Inset Grouped)
Can a plain style table view have sections?
Any tableview has sections
You are able to set style via Attributes inspector or via code UITableView(frame: <CGRect>, style: <UITableView.Style>) and can not be changed in runtime
Style defines a set of properties which setup some visual UI effects by default
Plain
doesn't have any setup
Grouped
It has tableHeaderView and title of section header is collapsed to it
Section has background from cell
Inset Grouped(from iOS v13, if you set via inspector for < v13 - Grouped will be used )
all from previous
section with corner radius(10). It is not possible to change
horizontal extra padding to cell(not for header). To change it use
self.tableView.layoutMargins = UIEdgeInsets(top: 0, left: 1, bottom:
0, right: 1) //if set to 0 - no corners with radius
Related
As you see above, I have a Table View on LeftSide which contains a Some Text.
But when i selected any annotation in map according to that the cell will be Highlighted & it has more text rather than other Cell and also background color is changed.
How can i achieve this?
You can approach in following way.
First both table data and annotation pins in Map are filled from an array!!
What you can do, you can define "tag" as array index to particular item.
When a user tap on a annotation, that annotation has a "tag" (or array index) and this "tag" (or array index) also has an item for table data.
On click of annotation tap, you have to reload your table and make that particular tableview cell highlighted.
You need to customize the UITableViewCell for this
Add a table view and map view in your view as shown in figure.
Load the custom table view cell to tableview
Initially give the needed color for all table cells
When user selects a cell change it's color
Using didSelectRowAtIndexPath: delegate method show the corresponding value on map.
Check this link for tutorials:
Appcoda
The basic sample for slide menu in iOS
https://github.com/nverinaud/NVSlideMenuController
Hope this sample code will helps you
I think you are creating custom annotation instead of the default one so if it is possible for you to set tag for each annotation view which will be same as tableview cell index. While selecting an annotation create indexpath with that tag and set selectedrow for that indexpath. Hope it may help you.
Create your customized class of UITableViewCell.
Understand you have two conditions A. Normal Cell B. Cell after the click.
You'll have to use 3 delegate methods of UITableView to achieve this.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here you'll have to check for the condition you'll have to check which indexPath.row is selected. and according to that you'll have to change the height of your row.
return hight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Again the same thing. You'll have to check the condition and load the appropriate controls with appropriate frames.
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// This is the important function for you.
// Here you'll have to set one counter. Which you'll use in the
// After that reload the table.
}
I have a custom separator style (fairly simple):
[[UITableView appearance] setSeparatorColor:SOMECOLOR];
Now I want to have my tableview finish with a separator. Currently separators only appear between two cells, but I want to have a separator at the end.
see here:
any ideas how this could be done?
I usually make my own separator inside the table view cell. I do this with a UIView that spans the width of the cell and is 1 or 2 points high.
In your case, if you want the system separator, you would have to add a custom cell at the end which is all transparent and 1 point high. UITableView would then add the missing separator.
I understand it you want a separator at the end as well? You can add a footer view to achieve this effect.
Make a footer view with height of 0.0001. To do so simply implement the following tableview delegate method :
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
}
I designed a uitable view like in the image below , I want to hide the part under the second section , which I write on it (<- I want to remove this part ->)
any suggestion to do that
If you coppied the code from someone, this element is the fotter view for the second section. Look for the method:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
end erase it. It should be out.
You can try creating the table with specific height in the Interface Builder or:
UITableView* pTable = [[UITableView alloc] initWithFrame:(CGRect)];
Maybe you can also specify that scrolling is forbidden in order to show the contents that you want:
pTable.scrollEnabled = NO;
You might want to implement tableView:heightForFooterInSection: and tableView:heightForRowAtIndexPath: and return heights for the footer of the current section and header of the next section to reduce the gap between the two sections. This of course, if there are sections are the current section. If there are no more sections, then you can just reduce the frame size.
I would like for my section header to display the sum of the values in my rows.
I therefore implement the:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
delegate function and place a UILabel in the custom view I build here.
If this were a UITableViewCell I would build the cell if it did not exist, then update it, or if it exists - only update it.
I don't know which "pattern" to use to update my Section Header.
Either there is a "right way" build into the UITableView, but I can't seem to find an "updateSectionHeaderForSection" and call this only when I change the value of a row.
What puzzles me is how the UITableView deals with headers, does it call viewForHeadersInSection only once on reloadData/instantiation or does it call it all the time, i.e. does it instantiate the view repeatedly when scrolling if I place this code in the viewController?:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImageView *shadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"topbar.png"]];
}
And how do I force the section header to update the view, like calling updateRowsAtIndexPaths, when I have changed the value it should display?
I can't seem to find Apples take on this in the UITableView Programming Guide.
Thanks in advance for any help given.
I had to do a similar thing recently, the way I did it was to draw a custom view in viewForHeaderInSection. This view contained a number of different components and for the label that I wanted to show the total in I gave it a tag
detailLabel.tag=100001;
Then, whenever I wanted to update the total I retrieve the associated view
UILabel *total = (UILabel*)[self.view viewWithTag:100001];
And update it to the value I wanted:
total.text = #"1234";
i have done like
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
tableview is in UITableViewStylePlain.but it shows correctly 3 data on 3 tableview cell.but after that there is empty tableview cells ...but when i declared UITableViewStyleGrouped, it shows only 3 tableview cells... perfectly...what i have to do disappear empty tableview cell
in UITableViewStylePlain..any help pls?
Your table contains 3 table cells and those cells beneath it are not empty table cells. The row seperators are just drawn based on the previous row height giving the impression that there are more cells than you actually specified.
You could set the separatorStyle of the table view to UITableViewCellSeparatorStyleNone, either in code or in Interface Builder. But doing so disables the seperators all together, so you would have to draw some kind of separator yourself in your cells if you still wanted a grafical separation between the actual cells.
Another option would be to set the color of the separator to the color of the background of the table.
I myself would not worry about this if you're application has a standard table look, as it's default behaviour & users should be used to seeing that. Altough I must admit that I have set the separatorStyle to none in a previous project, because the table had a look that deviated from the standard table look. I did have to draw a fine separator line at the bottom in the table cell.