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.
Related
I'm trying to use Autolayout and Interface Builder to create a custom TableViewCell. I setup my cell in viewDidLoad like this:
[tableView registerNib:[UINib nibWithNibName:#"BChatCell" bundle:Nil] forCellReuseIdentifier:#"ChatCell"];
Then I dequeue the cell like this:
- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath: (NSIndexPath *)indexPath {
BChatCell * cell = [tableView_ dequeueReusableCellWithIdentifier:#"ChatCell"];
return cell;
}
When the table view first loads it loads correctly:
However, after the table scrolls, Autolayout breaks:
Here are the constraints:
Any help would be greatly appreciated.
I had the exact same issue. Drove me crazy because everything looks great until the cells get reused.
I discovered that the view that was getting resized was not the cell itself (which is always screen width), but an inner content view I had. You're able to print all the constraints on any view with NSLog(#"%#", [theView constraints]); which helped with debugging
Also tried to no avail:
setting all the important views and subviews to translatesAutoresizingMaskIntoConstraints=NO
manually setting bounds inside -(void)prepareForReuse
calling setNeedsUpdateConstraints
The issue was that I had named my inner card view "contentView" which is already a named view in UITableViewCell. Changing it fixed the resizing issue.
The problem with your approach is the static leading and trailing. Your trailing constant is 200 and when you rotate it you want it to become more than that 200 (because of the width of the screen). This breaks the constraint and probably in the console is saying that you have ambiguity in your constraints and it did the automatically add a new one (which results in weird behavior).
So what I suggest is that to try making the trailing constraint Greater than or equal 200 and see if it works.
Another solution would be adding a width constraint for that blue view and removing the trailing constraint.
I hope this helps!
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 have a custom UITableView header which I want to be able to scroll above the top of the table. Normally the header would stick to the top of the table, is it not possible to somehow change to scrolling ability so that it can go beyond that and scrolls with the cells in the table?
Thanks.
Well if that is the desired behavior you want, just put the header as the first cell's content. It is possible to customize any particular cell you want. UITableViewDelegate documentaion will help you in that matter.
PS: the whole point of using tableView header is to make it stick to the top of the window.
EDIT: If it is necessary that you have to do the way you want, then you can try this: move your tableView a little down by setting its contentOffset. eg: myTableView.contentOffset= CGPointMake(0,heightOfYourView) . Now add yourView at the top
myTableView.tableViewHeader = myCustomTableHeaderView;
This would set myCustomTableHeaderView as the header of your table view and it would scroll with the table view.
By implementing tableView:viewForHeaderInSection: for section of index 0, you can instead have the header as the first section that should disappear when it scrolls. In this way, it's not a header for the whole UITableView.
If you only have one header for the whole table, can't you just set the tableHeaderView property?
You might, like me, have been searching for the tableHeaderView property. See this SO question for more info.
You should use Grouped TableView Style and in your ViewDidLoad method, add following line of code:
myTableView.backgroundColor=[UIColor clearColor];
myTableView.opaque=NO;
myTableView.backgroundView=nil;
Also in nib file, you should clear background color of grouped table;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;//Change as per your table header hight
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
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";
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