Customization tableView - objective-c

How I can add a bar with 3 UIButtons above a UITableView? Please, I need examples. I want to make it like this.

You can create a cell in your storyboard that contains a segment controller on it.
Now in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
You can dequeue that cell for the first on in the table.

In your viewDidLoad, create a UIView with a clear background colour.
Then, create a UISegmentedControl and add that as a subview to the clear view.
Finally, set your clear view as the table header view:
self.tableView.tableHeaderView = myClearView;

Bar is called as segmented control in iPhone.
To create it sub class UIViewControl class and add segmented control on top and then add UITableView below that better you can use Xib or you can find Coordinates and add both controls programatically.
refer to this link

you can do by implementing Header View Section delegate methods for your UITableView in your ViewController
In the following delegate method, give the size of your view you want to implement
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 60.0f;
}
Implement UISegmentedControl to get your three buttons and implement that in your viewForHeaderInSection method
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segments] autorelease];
segmentedControl.frame = GRectMake(60, 10, 200, 40);
........
// Do other Stuffs of Segmented Control
........
return segmentedControl;
}

Related

UITableViewCell UIButton dynamic height

I have CustomCellView which is custom view for cell in tableview. I have UIButton in xib and set it's default frame in xib.
In MainViewController (viewDidLoad)
// Get nib for custom cell
UINib *nib = [UINib nibWithNibName:#"CustomFeedCell" bundle:nil];
[self.mainTableView registerNib:nib forCellReuseIdentifier:#"CustomFeedCell"];
In cellForRow...
CustomFeedCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:#"CustomFeedCell"];
// here i need to set UIButton frame (height) depending on image height.
// I have tried diferent ways and it always return height set in CustomCellView xib
If you want to create buttons, images etc in UIView dynamically, you have to use viewDidLoad: method and do not use xibs.
Ok so what I am understanding from your question is you are having problem setting the dynamic height of a button present in your tableview cell. It sometimes might be more then the height of the cell and sometimes quiet less then height of the cell. And you want to adjust it accordingly. Correct ?
If thats your problem then you can set height of your each tableview cell in its delegate
tableView:heightForRowAtIndexPath:
as
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [indexPath row] * 20; // your desired height
}
Hope this solves your problem.

How to make UITableView look like the one in Contacts?

I'm trying to make UITableViewController look like following.
(it has picture and several rows for someone's identify.)
I wonder how to make like following programmatically.
How to adjust UITableViewCell's origin.x and width?
How to add a picture at left top?
Please help me.. I will thank you.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier];
cell.frame = CGRectMake(50, 0, 250, 44) <--- ?????? I think this is wrong way.
return cell;
}
My best bet is that either there are two static UITableViews inside a UIScrollView or that it's some custom subclass UIView set as tableHeaderView and styled to look as on the picture. If I were to implement it I'd go with the second choice.
Make a subclass of UITableView. Give your subclass properties referring to the photo well and the three special row cells.
Override layoutSubviews to call [super layoutSubviews] and then set the frames of the photo well and the three special row cells.
The photo well should not be a cell.

UITableView custom section header disappear

I have a view that I'm trying to use as a header section of my UITableView.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *name= (UILabel *)[myView viewWithTag:200];
name.text = #"title";
myView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"row-bg-red.png"]];
return myView;
}
It loads ok, but when I scroll down and the next header appears, the previous does the opposite: it disappears.
Any suggestion?
I guess you reuse the one view. This is not possible. Each view (UIView subclass) can be in the view hierarchy exactly once. So what probably happens in your case is that when you set the second section view, it gets removed from its original place where you put it last time for the first section.
You can create every time a new section header view directly in - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section method.

Several TableView questions

I am looking to create a similar interface to the iTunes iPhone app search interface. I have a few questions I can't seem to find an answer for:
Here is an image of the iTunes iPhone app search interface in question:
How do I create the tableView section subtitle, e.g. the Tap to Preview, Double-Tap to View info under the Top Hits section title.
How is the price button created to float right? Is this done natively or using a custom UIView?
Finally how would I differentiate between a single tap and double tap on any of the table view cells?
You will need to create a Custom UITableViewCell, here's a tutorial. for the price button and other visuals of the cell.
As for the Tap to Preview subtitle, you can create a custom header view, see:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Most likely, you would need to create 2 UILabels for this view, and obviously you would want to match the fonts used here.
An Example
- (UIView *) tableview:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = #"Top Hits";
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:17];
[headerView addSubview:label];
UILabel * label2 = [[UILabel alloc] initWithFrame:CGRectZero];
label2.text = #"Tap to Preview, Blah blah blah";
label2.backgroundColor = [UIColor clearColor];
label2.font = [UIFont fontWithName:#"Apple's Default Font?" size:17];
[headerView addSubview:label2];
/* something like this */
return headerView;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50.0f;
}
Most of your questions are address well in Apple's Table View Programming Guide for iOS. Here are some short answers:
You can make a header for a section be a UIView, in which case you can use multiple UILabels to create titles with subtitles and the like.
This is probably set as the accessoryView of the UITableViewCell, or it may be an entirely custom subclass of UITableViewCell.
For this, you'll need to implement the UITableViewDelegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. For more on customizing this method (e.g. to differentiate between single and mutliple taps), check out the Managing Selections section of the above tutorial.
1-For the Custom header
you can use the table view datasource method
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
and then you can either create the view programmtically with all the labels
or you can make an seperate view in the xib ,create its instance in your viewcontroller and return that instance in the above datasource method- this approach would be much easier and simpler.
2- You can implement the price button by using a uibutton and setting it an background image
in a custom table view cell. you can hide/unhide this button as per your functionality.
3- I would suggest you to disable the tableview selection and add tap gesture recognizers to the custom table view cell. this would give you more flexibility
Hope this could help you

Hiding a UIView

I have several UIViews that are on my xib file and would like to dynamically hide them when I want. I have the following code below but for some reason it's not hiding them. Any ideas what I could do?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//hide all the static UIviews
_searchBox.hidden = YES;
_searchButton.hidden = YES;
_logo.hidden = YES;
NSLog(#"FIRED THE EVENT");
//TODO: create a new view that holds a zoomed in image
}
Are theses items IBOutlet connected to the ones in your nib file? And are the referencing outlets linked? That is usually the cause.