Sticky UITableView header like App Store Featured page in iOS? - ios

How do I imitate this behavior in UITableView. Wherein, if I pull the table DOWN, the header sticks at the stop, but if I scroll the table UP, the header goes with it.
Like the app store.
(scrolling up)
(scrolling down)

You can use tableHeaderView for this type of work.
In your viewDidLoad write below code.
- (void)viewDidLoad
{
**// Take one view and subview that view in the tableview.**
UIView *viewsearch=[[UIView alloc]initWithFrame:CGRectMake(0,-10, 320,83)];
[self.Yourtablename addSubview:viewsearch];
**//Now take any controls which you want to show in your header. e.x label,button,searchbar**
UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor whiteColor];
lbl1.userInteractionEnabled=YES;
[viewsearch addSubview:lbl1];
lbl1.text= #"BUY THE NEW APPLE TV FROM THE APPSTORE";
**//Here is the code.With the help of this code when you scroll UP the headerview hide.**
self.tbluser.tableHeaderView = viewsearch;
self.tbluser.contentOffset = CGPointMake(0, CGRectGetHeight(viewsearch.frame));
}
May be it will help you.

Related

How to keep the UI-Searchbar visible when user slide upward in tableview

In my app when the user slide down the UI-searchbar become disappear, which I want but when the user slide up I want UI-Search bar become visible at once.
I want to have code that tell me when the user had slide upward in tableview cell and enable the uisearch-bar.
You can use tableHeaderView for this type of work.
In your viewDidLoad write below code.
- (void)viewDidLoad
{
**// Take one view and subview that view in the tableview.**
UIView *viewsearch=[[UIView alloc]initWithFrame:CGRectMake(0,-10, 320,83)];
[self.Yourtablename addSubview:viewsearch];
**//Now take any controls which you want to show in your header. e.x label,button,searchbar**
UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor whiteColor];
lbl1.userInteractionEnabled=YES;
[viewsearch addSubview:lbl1];
lbl1.text= #"BUY THE NEW APPLE TV FROM THE APPSTORE";
**//Here is the code.With the help of this code when you scroll UP the headerview hide.**
self.Yourtablename.tableHeaderView = viewsearch;
self.Yourtablename.contentOffset = CGPointMake(0, CGRectGetHeight(viewsearch.frame));
}
May be it will help you.

Presenting a semi-transparent UITableView from a UIViewController

I'm working on an app that will rely on one main view controller with a row of buttons at the bottom to display other views with information. From one of these buttons I want to present a tableview that presents a list of song titles. This app plays sound files, and I want the user to be able to tap a button, then select a song to be the default song to play. I want to present this tableview with a uiview animation, and I want it to be semi-transparent and only fill a portion of the screen. I've tried creating a UITableViewController and then presenting it from the main view controller like so:
UITableViewController *tableView = [[UITableViewController alloc]init];
[self presentViewController:tableView animated:YES completion:nil];
This presents a view controller that fills the entire screen though, which is not what I want. And changing the view controller's frame at instantiation time doesn't seem to have an effect. I can just animate a UITableView into the main view controller's view, but then I'm not so sure who is supposed to be the delegate and data source. Any suggestions? Thanks in advance.
While adding table view as a subview, u can set its frame size or bound, and display it with animation whatever you like. Yes, you can set delegate and datasource to self while adding .
I use: (in viewDidLoad)
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
Then in cellForRowAtIndexPath:
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];
Not sure if this is what you wanted, but it gives you the option to make everything clear. (obviously the alpha would change for your case, but that measures the opacity of the cells)

Place UIView At Finite Location on Screen with UITableView

I have a tableview that takes up more than the screen. Certain rows have an info button on them. When these are pressed, I want to give the user a message based on which row the info button was on. I want to show this message in a basic UIView that appears at the same spot on the screen every time (somewhat like a UIAlertView).
My problem is specifying the frame for the UIView so that it will show with the origin at a particular location on the screen. Trying to set the frame self.view.frame or [UIScreen mainScreen].bounds results in using the bounds of the whole scrollView or just the first visible element of the scrollView.
How can I make the view always appear in the same screen location?
You need to pass a static frame to your custom view. Like this
in didSelectRowAtIndexPathMethod
try this code ----
UIView *infoView = [[UIView alloc] initWithFrame:CGRectMake(10,10,100,100)];
UILabel *lblInfo = [UILabel alloc] initWithFrame:CGRectMake(5,5,40,21)];
lblInfo.text = #"your text here";
[infoView addSubView:lblInfo];
[lblInfo release];
[self.view addSubView:infoView];
[infoView release];

iOS UITableView: UIView/custom cell at the bottom like in twitter iPad app

I am creating an iPad app using the master-detail template available in Xcode 4.3. My master tableview is acting as a navigation menu for the detail view and the menu items will be fixed. So I basically don't exactly need the scrolling view, thus I have turned it off.
self.tableView.scrollEnabled = NO;
Now I have a requirement to display a footer like cell aligned at the bottom of master menu just like in Twitter iPad app. The cell should appear at the bottom in landscape as well as portrait modes. Can somebody give me some hints regarding how to implement this?
I read on some blogs about using a UIView and setting it to UITableView.tableFooterView, something like this...
// I'll have to do calculations of frame height/x/y for both orientations
// to make the view appear at bottom - IS THERE A SIMPLER WAY???
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 944, self.tableView.frame.size.width, 60)];
UILabel *logo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 60)];
logo.text = #"This is the Footer.";
[footerView addSubview:logo];
self.tableView.tableFooterView = footerView;
After looking at the app, I don't think the "footer" is part of the table. It looks more like a small view under the table. So the table is set up so it will stretch vertically but it's height is locked above the bottom view. Maybe it would be better to use a UIViewController and a UIView for you Master View instead of a UITableViewController. Then put your UITableView in the UIView and put your footer below it. Then configure the UIViewController to work with the UITableView as it did before.
Hope this helps.

Transparent background for the Group Table Cell

For group table cell, I fall into this problem.
cell.backgroundColor=[UIColor clearColor]
make the cell bg black. It works for normal cell, not for group table cell.
I want to add some button, e.g. like the detail view of iPhone contact with transparent background.
If anybody face the problem, I got a solution, set a transparent view as a background view of the cell. Then it becomes totally transparent. Then you can add more view or customize the cell.
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
messageCell.backgroundView = backView;
messageCell.contentView.layer.cornerRadius = 10.0;
messageCell.contentView.layer.borderWidth = 1.0f;
messageCell.contentView.layer.borderColor = [[Settings getInstance] colorFrameBorder].CGColor;
messageCell.selectionStyle = UITableViewCellSelectionStyleNone;
return messageCell;
This solution was quoted in one of the StackOverflow question, which I cant remember.
I have also found that, its easy to add a transparent view in the table header or footer. The button down the contact details are probably added in a footer view.
From the looks of it I'd say you are setting a background image to your cell. You can see it at each cell on the right side, there are the stripes from your view background.
Remove the cell's background and you should be fine.
I found the solution from this answer here by setting cell's backgroundView
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
I would take Charles's answer one step further and do the following
self.myTableView.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];

Resources