【问题标题】:IPhone Plain TableView Section Header Image and Getting Text on Two LinesiPhone 普通 TableView 部分标题图像和两行获取文本
【发布时间】:2010-02-13 03:36:15
【问题描述】:

这是我的第一个问题,所以如果我没有正确地做标签,我很抱歉。我试过......好吧,这是我的问题:我希望有人能告诉我如何为一个普通的表格视图做一个两行的部分标题。我遇到的问题是:1)我找不到可以模仿默认 1 行节标题的图像。有人可以和我分享一个吗,或者告诉我如何找到一个? 2)我似乎无法在两行上获取节标题文本,因为我是从获取的结果控制器中提取的,这是我在类上为我的表自定义定义的“字段”(对不起,如果术语错误)。所以这个“字段”中有多个字段值,我无法将它们分开......任何帮助将不胜感激。

【问题讨论】:

    标签: iphone cocoa xcode


    【解决方案1】:
    if(section == 1)
            return @"\nText on line one\nText on line two\nText on line three";
    

    你实际上可以有几行使用 \n

    【讨论】:

      【解决方案2】:

      使用这些方法(这个代码示例应该可以工作):

      - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
          UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 280, 40)];
          label.numberOfLines = 2;
          label.text = @"line 1\nline 2\n";
          return [label autorelease];
      }
      
      - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
          return 44.0;
      }
      

      - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 方法仅适用于单行文本。请注意,生成的框架具有 0,0 原点和指定的高度;将调整原点以正确放置标题,并通过以下方法设置高度。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-28
        相关资源
        最近更新 更多