【问题标题】:How to Create a Table like the below如何创建如下表
【发布时间】:2012-04-11 18:28:27
【问题描述】:

我创建了一个 TableView(分组表视图)。我可以在表格视图中列出项目。但是我想知道下表是如何显示的

就像日历在左侧,而公历在右侧??格里高利如何显示在右侧?它是自定义 TableView,谁能帮我实现它?

【问题讨论】:

    标签: iphone xcode uitableview cocoa-touch uikit


    【解决方案1】:

    这些只是带有style = UITableViewCellStyleValue1accessoryType = UITableViewCellAccessoryDisclosureIndicator 的常规单元格。

    以编程方式制作:

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YourIdentifier"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    

    (请注意,在现实生活中您可能会尝试dequeueReusableCellWithIdentifier:,并且只有在返回 nil 时才创建一个新单元格。)

    或者,如果您正在使用 IB,请将“样式”设置为“正确的细节”,将“附件”设置为“披露指示符”。

    【讨论】:

    • 样式来了,但是India,Gregorian等第二个文字怎么显示??
    • cell.detailTextLabel.text = @"like, whatever"
    【解决方案2】:

    您需要使用以下代码帮助您

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            UIImageView *v = [[[UIImageView alloc] init]autorelease];
            v.backgroundColor = [UIColor clearColor]; // put clear color
            [v setClipsToBounds:YES];
            cell.selectedBackgroundView = v;
            [cell setClipsToBounds:YES];
        }
        UIImageView *imgVBG=(UIImageView*)[cell selectedBackgroundView];
        if(indexPath.row==0){
            imgVBG.image=[UIImage imageNamed:@"TopImg.png"];
        } else if((indexPath.section==0 && indexPath.row==4)||(indexPath.section==1 && indexPath.row==7)){
            imgVBG.image=[UIImage imageNamed:@"BottomImg.png"];
        } else {
            imgVBG.image=[UIImage imageNamed:@"MiddleImg.png"];
        }
    }
    

    【讨论】:

    • 只有前 6 行与问题相关,与 Yuji 已经发布的内容没有什么不同。
    • @jrurton :但是在不同的代码中,您的 uitableview 使用效率更高,所以它就在这里
    • 谢谢,对我很有帮助!
    【解决方案3】:
    猜你喜欢
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 2019-10-20
    相关资源
    最近更新 更多