2011-12-01 5 views
3

나는 표 셀의 높이를 콘텐츠 높이에 맞게 만드는 방법을 알아 내기 위해 인터넷 서핑을 해왔다.Monotouch : UITableViewCell height

나는이 샘플을 보려고 노력했다 .... http://simon.nureality.ca/simon-says-project-d-uitableviewcells-autosize-based-on-text-height-in-monotouch-heres-how/ ...하지만 나는 그것을 작동시킬 수 없다.

은 여기까지 .. 셀 높이가 실제로 작동하고 내 코드지만, 텍스트 (대신 전체 프레임을 dilling의) dotts를 trailling와 중심 :

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) 
{ 
    string item = this.Lst.Items [indexPath.Section]; 

    UITableViewCell cell = tableView.DequeueReusableCell (_cellIdentifier); 
    if (cell == null) { 
     cell = new UITableViewCell (UITableViewCellStyle.Default, _cellIdentifier); 
     cell = new UITableViewCell (UITableViewCellStyle.Subtitle, _cellIdentifier); 
    } 

    // Find the height... 
    SizeF textWidth = new SizeF (tableView.Bounds.Width - 40, float.MaxValue); 
    SizeF textSize = tableView.StringSize(item, Font, textWidth, LineBreakMode); 

    // Textlabel... 
    cell.TextLabel.Text = item; 
    cell.TextLabel.Font = Font; 
    cell.TextLabel.Frame = new RectangleF(cell.TextLabel.Frame.X, cell.TextLabel.Frame.Y, textSize.Width, textSize.Height); 

    //cell.Accessory = UITableViewCellAccessory.DisclosureIndicator; 
    cell.ImageView.Image = PlaceholderImage; 
    cell.EditingAccessory = UITableViewCellAccessory.DisclosureIndicator; 

    // Sizing the cell... 
    RectangleF rectCell = cell.Frame; 
    rectCell.Height = textSize.Height; 
    cell.Frame = rectCell; 

    return cell; 
} 

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath) 
{ 
    string item = this.Lst.Items [indexPath.Section]; 
    SizeF size = new SizeF (tableView.Bounds.Width - 40, float.MaxValue); 
    float height = tableView.StringSize (item, Font, size, LineBreakMode).Height + 10; 
    return height; 
} 

을 그리고는 다음과 같습니다 .. .

enter image description here

잘못 어떤 생각?

감사합니다.

모조

+0

셀의 ContentView의 일부로 UILabel을 추가 할 수 있습니까? TextLabel 프레임을 조작하는 것보다 훨씬 쉬울 것 같습니다. – Anuj

+0

Emmm dunno (이게 나에게 새로운 것) : – MojoDK

답변

3

당신은 LinesLineBreakMode 속성을 설정하여 textLabel라는의 동작을 제어 할 수 있습니다. 레이블이 줄 바꿈을하고 필요한만큼의 라인을 사용하게됩니다

cell.TextLabel.Lines = 0; 
cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap; 

설정 예를 들어

.

Miguel De Icaza가 MonoTouch.Dialog을 사용하는 것을 고려해보십시오. 그것은 UITableView 다루는 것을 상당히 단순화합니다.

+0

고마워요. 이제 텍스트가 좋아 보이네요. 텍스트가 고색인데 왜 이미지에 왼쪽 패딩이 있습니까? – MojoDK

+0

MonoTouch.Dialog로 "MoveRow"하는 방법을 알아낼 수 없습니다. – MojoDK

+0

Havent 자신이 해냈습니다. 그러나 테이블에 사용되는 기본 데이터 구조를 업데이트하는 것, 즉 목록에서 요소를 제거하고 다른 곳에 삽입하는 것만이 아닙니까? – Ryan