开发者

Several TableView questions

I am looking to create a similar interface to the iTunes iPhone app search interface. I ha开发者_如何学Cve 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:

Several TableView questions

  • 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:

  1. 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.

  2. This is probably set as the accessoryView of the UITableViewCell, or it may be an entirely custom subclass of UITableViewCell.

  3. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜