如何实现这种样式表

时间:2011-08-24 06:57:16

标签: iphone objective-c

enter image description here

单元格内有表格,可以点击每个小单元格来触发另一页面。

3 个答案:

答案 0 :(得分:0)

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSString* cellIdentifier = @"cellIdentifier";   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    UIButton* tempBtn1;     
    UIButton* tempBtn2;     

    if(cell == nil)
    {
        cell = (UITableViewCell*) [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

        tempBtn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        tempBtn1.tag = 123;
        tempBtn1.frame = CGRectMake(0, 0, 160, 44);
        [tempBtn1 setTitle:@"firstBtn" forState:UIControlStateNormal];
        [cell.contentView addSubview:tempBtn1];

        tempBtn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        tempBtn2.tag = 234;
        tempBtn2.frame = CGRectMake(160, 0, 160, 44);
        [tempBtn2 setTitle:@"secondBtn" forState:UIControlStateNormal];
        [cell.contentView addSubview:tempBtn2];     
    }
    else {
        tempBtn1 = (UIButton*)[cell.contentView viewWithTag:123];       
        [cell.contentView addSubview:tempBtn1];         
        tempBtn2 = (UIButton*)[cell.contentView viewWithTag:234];       
        [cell.contentView addSubview:tempBtn2];     
    }

    return cell; 
}

答案 1 :(得分:0)

创建一个UIView子类。这将代表一个项目(单元格内容的1/2)。在每个单元格中添加其中两个。检测此UIView子类中的触摸并在获得触摸事件时推送新的ViewController。

答案 2 :(得分:0)

这看起来像Twitter应用程序。

我认为,这些方法可能会对您有所帮助:

  • 创建一个带有2个数字和文本标签的UIView;将其命名为labelView
  • 按一个按钮[UIButton alloc] buttonWithType: UIButtonTypeCustom]
  • 将您的lableView添加为此按钮的子视图。
  • 使用2个按钮制作一个单元格:并排
  • 制作分隔符:#import <QuartzCore/QuartzCore.h>,然后

    labelView.layer.borderSize = 1;

    labelView.layer.borderColor = [UIColor grayColor].CGColor;

  • 手动将按钮移动到合适的位置。您可能想要使用:cell.contentView.clipsToBounds = YES

希望得到这个帮助。

相关问题