2013-07-03 5 views
2

나는 다음과 같은 CustomCell 있습니다자 마린 Monotouch CustomCell는 비어

using System; 
using System.Drawing; 
using MonoTouch.Foundation; 
using MonoTouch.UIKit; 

namespace Zurfers.Mobile.iOS 
{ 
    public class CustomCell : UITableViewCell 
    { 
     UILabel headingLabel, subheadingLabel, priceLabel; 
     UIImageView imageService; 
     UIImageView star, star2, star3, star4, star5; 
     public CustomCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId) 
     { 
      imageService = new UIImageView(); 
      star = new UIImageView(); 
      star2 = new UIImageView(); 
      star3 = new UIImageView(); 
      star4 = new UIImageView(); 
      star5 = new UIImageView(); 
      headingLabel = new UILabel(){ 
       Font = UIFont.FromName("Cochin-BoldItalic", 22f), 
       TextColor = UIColor.FromRGB (127, 51, 0), 
      }; 
      subheadingLabel = new UILabel(){ 
       Font = UIFont.FromName("Cochin-BoldItalic", 22f), 
       TextColor = UIColor.FromRGB (127, 51, 0), 
      }; 
      priceLabel = new UILabel(){ 
       Font = UIFont.FromName("Cochin-BoldItalic", 22f), 
       TextColor = UIColor.FromRGB (127, 51, 0), 
      }; 
     } 

     public void UpdateCell (string title, string subtitle, string price, UIImage image) 
     { 
      imageService.Image = image; 
      headingLabel.Text = title; 
      subheadingLabel.Text = subtitle; 
      priceLabel.Text = price; 
     } 

     public override void LayoutSubviews() 
     { 
      base.LayoutSubviews(); 
      imageService.Frame = new RectangleF(63, 5, 33, 33); 
      headingLabel.Frame = new RectangleF(5, 4, 63, 25); 
      subheadingLabel.Frame = new RectangleF(100, 18, 100, 20); 
      priceLabel.Frame = new RectangleF(250, 18, 100, 20); 
     } 
    } 
} 

그리고 이것은 내 TableSource입니다 :

using System; 
using MonoTouch.Foundation; 
using MonoTouch.UIKit; 

namespace Zurfers.Mobile.iOS 
{ 
    public class HotelTableSource : UITableViewSource 
    { 

     string[] tableItems; 
     NSString cellIdentifier = new NSString("TableCell"); 

     public HotelTableSource (string[] items) 
     { 
      tableItems = items; 
     } 
     public override int RowsInSection (UITableView tableview, int section) 
     { 
      return tableItems.Length; 
     } 

     public override void RowSelected (UITableView tableView, NSIndexPath indexPath) 
     { 
      new UIAlertView("Row Selected", tableItems[indexPath.Row], null, "OK", null).Show(); 
      tableView.DeselectRow (indexPath, true); // normal iOS behaviour is to remove the blue highlight 
     } 

     public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
     { 

      CustomCell cell = tableView.DequeueReusableCell(cellIdentifier) as CustomCell; 
      if (cell == null) 
       cell = new CustomCell(cellIdentifier); 
      cell.UpdateCell(tableItems[indexPath.Row], tableItems[indexPath.Row], tableItems[indexPath.Row], 
          UIImage.FromFile (tableItems[indexPath.Row])); 
      return cell; 


     } 
    } 
} 

하지만 응용 프로그램을 실행할 때의 TableView가 비어 있습니다. 각 CustomCell에는 TableView를 만들기 전에 값이 있습니다.

내가 뭘 잘못하고 있니?

미리 도움을 주셔서 감사합니다.

답변

4

세포는 컨트롤을 포함 할뿐만 아니라 컨트롤을 포함해야합니다 (또는 ContentView). 당신이 사용자 정의 셀에 추가하는 모든 컨트롤에 대한 AddSubview 전화 :

ImageService = new UIImageView(); 
AddSubview(ImageService); 

도움이되지 않는 경우 일부 데이터를 표시 UITableViewCell의 기본 컨트롤 (TextLabel, DetailTextLabel, ImageView)를 사용하려고 . 데이터가 나타나면 사용자 정의 UITableViewCell에 여전히 문제가 있습니다 (잘못된 프레임, 빈 텍스트). 그렇지 않은 경우 문제는 UITableViewSource (빈 데이터)입니다.

+0

감사합니다. addSubview가 작동합니다. – Jean