Fixed row in UITableView - ios

I would like to implement a UITableView / UITableViewController which has a fixed row on top - to search/add contacts. I probably could add an UIView first and an UITableView after to achieve this - I'm not sure if there's a better way to do this. Does anyone know a better solution here ?
what it should look like (e.g. whatsapp)

Yes, you could add an UIView first and an UITableView after for fixing your top row, this is the right solution for this.

You can set a view as headerView of the table view. Have a look at the docs from Apple:
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/tableHeaderView
UIView *searchContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
self.tableView.tableHeaderView = searchContainer;

Yes ofcourse,
Take 2 tableviewCell.
make 1 static and fill up with information u want in its Class file,
make another dynamic(basically the reuseable id) and work on it,in the tableviewController.
Position the cells accordingly in the storyboard before u start coding.

Related

UITableView cell separator line thicker?

I have attached an image of cells in a table view, and you can notice the 2 separator lines in the middle are a tiny bit thicker/darker than the 2 outer lines. I want the lines to all be consistent, and the color/thickness of the outer two lines. I could not find a solution, so I am wondering if anyone knows of any. I figure it would be a simple solution, but I haven't been able to figure it out. Thanks guys.
Select your UITableView from xib or storyboard, then make the UITableView separator to None.
See the image
Then place a UILabel with the width same as of UITableViewCell and height=1 in the bottom of your cell, clear the text of the label and set the backGround color as per your wish, this will solve your problem.
Hope this helps you.
Create a custom separator Line Programatically:
UIView *separatorLine = [[UIView alloc] initWithFrame:
CGRectMake(0, cell.contentView.frame.size.height - 1.0,
cell.contentView.frame.size.width, 1)];
separatorLine.backgroundColor = [UIColor blackColor];;
[cell.contentView addSubview: separatorLine];
or you can add a image view for separator in custom UITableviewCell in UI

Adding TableFooterView makes my other views Disappear

My first problem that i had was that my last UITableViewCell never had a separator which i wanted. I solved it using this code:
self.tableView.tableFooterView = [[UIView alloc] init];
Now that worked perfectly however with one problem. when i add that all my other views disappear. Here is a picture of before i use the one line of code above and after:
How can i fix this?
Set a zero height table footer view, like so:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for.
Have you tried to use the viewForFooterInSection function?
Add a vertical spacing of 0 between your table view bottom and the view's top which is placed below it. And you need to set one view's height fixed either for UITableView or UIView. Add this code of line in viewDidLoad. It will display the separator also for last cell.
self.tableView.tableFooterView = [UIView new];
Screenshot:
May be this help
You have to set translucent property of tab bar controller
see this question to more reference...
iOS 7 TabBar Translucent issue

Gap at top of UITableView with PLAIN cells

Does anyone know why a UITableView inside a UIViewController always has a gap above the UITableViewCell. I'm aware that this is expected for Grouped cells, but this is a Plain cell.
How can I remove the gap?
[[self UITableView] setContentInset:UIEdgeInsetsMake(-65, 0, 0, 0)];
That did the trick for me.
One of the proposed answers to the quesion UITableView is getting a gap on top solved this for me, although it's not the approved answer.
Just add this code in ViewDidLoad
self.automaticallyAdjustsScrollViewInsets = NO;
Alternatively, you can set this property on the ViewController in the storyboard.

How to put a UITableView below a UILabel with code

I wrote a code with a UILabel with the name of a meteorological station. Later, I added the code to put a UITableView with a grid view like this website explains http://www.recursiveawesome.com/blog/2011/04/06/creating-a-grid-view-in-ios/
The problem is that now the Table view is shown in all screen and the label can't be seen.
How do I make to put the elements in this order?
UILabel
UITableView
Thanks!
1 With a nib:
If you use a nib you can simply size / layout your label and table view so that they are positioned as desired. A UITableView can be made any size and take up any portion of the screen.
2 Without a nib
Create / alloc / initialize your label and table, and then add them to the view:
[self.view addSubview:myTableView];
[self.view addSubview:myLabel];
The magic step to this is that you need to set the frame of both your label and table view. Thats something that is really custom so I cant help you with that without more direction however it may look something like this:
// the number 10 is used for padding purposes
CGSize labelWidth = CGSizeMake(self.view.frame.size.width-20, 1000.0f);
CGSize textSize = [myLable.text sizeWithFont:myLable.font constrainedToSize:labelWidth lineBreakMode:UILineBreakModeWordWrap];
myLable.frame = CGRectMake(10, 10, labelWidth.width, textSize.height);
myTableView.frame = CGRectMake(0, myLable.frame.origin.y+10, self.view.frame.size.width, self.view.frame.size.height - (myLable.frame.origin.y+10));
Please note that calculating frames can be done MANY ways. Also you will probably have to recalculate the frames manually for rotations.
Hope this helps Good Luck!
Depending on the answer to my questions in the comments, there are several answers.
If you want the label to always be on top whether or not the tableview is scrolled, make sure you are using an instance of UIViewController, then create your two views. Set the frame appropriately and then add the label view and the table view as subviews to the main view.
If you want the label to scroll away, that's even easier. Your UIViewController can remain a subclass of UITableViewController. UITableView has a property called tableHeaderView. myTableView.tableHeaderView = labelView;
You could to like Rachel said
[self.view addSubview:myTableView];
[self.view addSubview:myLabel];
or after placing it
[self.view bringSubviewToFront:myTableView]

Can't get UILabel to show properly on top of UITableView

I am struggling to achieve what I thought was nothing but a 1' coding but apparently
adding a UILabel above my UITableView in a UITableViewController is not a piece of cake...?
Here is the code (yes basic, I know):
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 310, 20)];
[[self tableView] addSubview:label];
The result can be seen in the screenshot below, the label on the top right is just half displayed, saying "Balance..."
Please note that if I try to change CGRect origin.y or size.height the UILabel is not displayed at all.
I also tried adding the following, with no change in result:
[[self tableView] bringSubviewToFront:balanceLabel];
I don't care if the UILabel is scrolled up when scrolling up the UITableView, I want it to stick with the first section header.
I know this can be achieved in other ways, using a custom UIView for the header, changing to UIViewController or using a .xib, but really I would like to understand why this happens.
Thanks for any help.
F.
It does look like the header is hiding your label, maybe you could try setting the header background to clearColor. Since you have no control on the table view loop I suspect that after your addSubView somewhere the table builds its own header and does another addSubView.

Resources