簡體   English   中英

TableView 單元格框架問題

[英]TableView cell frame problem

我正在開發一個具有如圖所示視圖的應用程序。 我有一個表格視圖。 我的問題是如何將我的聊天框單元格顯示在原始表格視單元框架的右側。

像白框是原始表格視圖單元格的某些權利

代碼:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    int row = [indexPath section];

    UITableViewCell *startCell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(10, 0, 200, 50)  reuseIdentifier:CellIdentifier] autorelease];
    UITableViewCell *durationCell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(50, 0, 200, 100) reuseIdentifier:CellIdentifier] autorelease];
    UITableViewCell *radiusCell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(100, 0, 200, 150) reuseIdentifier:CellIdentifier] autorelease];

    startCell.textLabel.text = @"Start:";
    durationCell.textLabel.text = @"Duration:";
    radiusCell.textLabel.text = @"radius";


    if (row == 0)
    {
        return startCell;
    }
    else if (row == 1)
    {
        return durationCell;
    }

    return radiusCell;


}

您需要在 cellForRowAtIndexPath 方法中設置單元格內的視圖框架,或者您可以在任何地方制作自定義單元格和 position。

如果您的單元格包含 UIImageView 那么您必須創建自定義單元格。 在自定義單元格的 sm 文件中,您必須在該方法中創建一個名為- (void)layoutSubviews的方法,為圖像視圖編寫代碼,例如

   `CGRectMake frame= CGRectMake(5, 12, 19, 15);    
    myImageView.frame = frame;`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM