2013-02-21 3 views
0

내 iPhone 응용 프로그램에 대한 사용자 정의 테이블 셀을 Monodevelop 및 xcode 4를 기반으로 모노 터치를 기반으로 만들고 싶습니다. 나는이 같은 클래스를 생성이이 기사에 의해monodevelop 및 Xcode를 사용하여 사용자 정의 표 셀 만들기

http://www.alexyork.net/blog/2011/07/18/creating-custom-uitableviewcells-with-monotouch-the-correct-way/

http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html

을 : 나는이 기사를 발견

[Register("ListingCell")] 
public partial class ListingCell : UITableViewCell 
{ 
    public ListingCell() : base() 
    { 
    } 

    public ListingCell (IntPtr handle) : base(handle) 
    { 

    } 

    public void BindDataToCell(DrivedProperty _property) 
    { 
     LocatoinLbl.Text = _property .LocationString ; 

    } 
    public void AddImageToCell(UIImage _image){ 
     ListingThumbnail .Image = _image ; 
    } 
} 

과 내 UITableViewCell 및 정의 아울렛을 설계했습니다.

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
     { 
      ListingCell cell; 
cell = (ListingCell) tableView.DequeueReusableCell (identifier) ; 
      if (cell == null) { 
       cell = new ListingCell(); 
       var views = NSBundle.MainBundle.LoadNib("ListingCell", cell, null); 
       cell = Runtime.GetNSObject(views.ValueAt(0)) as ListingCell; 
      } 
var item = Controller.Items [indexPath.Row]; 
      cell.Tag = indexPath.Row; 
      cell .BindDataToCell (item); 
cell.AddImageToCell (item .Image); 
return cell; 
     } 

지금, 응용 프로그램이 잘 구축,하지만 난 실행할 때 debuger이 라인에 오류를 가져옵니다 :

var views = NSBundle.MainBundle.LoadNib("ListingCell", cell, null); 

과 말 :

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/john/Library/Application Support/iPhone Simulator/6.0/Applications/08FFAA89-4AC4-490D-9C1A-4DE4CBC6EBB7/Realtyna_iPhone_Project.app> (loaded)' with name 'ListingCell' 
그럼 내 GetCell 방법으로이 같은 코드를 사용

Realy 나는 이것을 모릅니다. 내가 그것을 삭제할 때. 응용 프로그램은 내 ListingCell 클래스의 셀 객체와 arror를 만듭니다. 인터넷에서 많은 검색을 수행했지만 해결책을 찾지 못했습니다. 어떤 몸이라도 이것에 대해 어떤 생각을 가지고 있습니까?

프로그래밍 방식으로 사용자 지정 셀을 만들 수 있음을 알게되었습니다. 작동하지만 문제는 런타임에 프로그래밍 방식으로 어려운 셀을 만드는 것이 어렵다는 것입니다. excode로이 세포를 만드는 것은 간단하지만 왜 작동하지 않는지 알지 못합니다. -S

답변

0

나는 당신이보고있는 문제가 무엇인지 잘 모르겠습니다.

그러나 iOS6에만있는 경우 LoadNib 코드 대신 NIB를 등록하고 표 셀을 dequeuing하기위한 새 API로 전환하면 도움이 될 수 있습니다.

전환 작업이 내 코드 작업을 훨씬 더 안정적으로 수행하는 데 도움이되었음을 발견했습니다.

그래서, 당신의 셀룰라 등록 :

tableView.RegisterNibForCellReuse(UINib.FromName("ListingCell", NSBundle.MainBundle), ListingCell.Identifier); 
그런

에 디큐 코드를 변경 :

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
{ 
    ListingCell cell = (ListingCell) tableView.DequeueReusableCell (ListingCell.Identifier, indexPath) ; 
    var item = Controller.Items [indexPath.Row]; 
    cell.Tag = indexPath.Row; 
    cell .BindDataToCell (item); 
    cell.AddImageToCell (item .Image); 
    return cell; 
} 

이것은 당신이 언급 한 기사 중 하나를 기반으로 - http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html (면책 조항 - 내가 쓴!)


정말 내가 돈 ' 당신이 공격 할 수 냄새처럼 -

을 제외하고

> 귀하의 AddImageToCell 코드가 나에게 잘못 냄새 ... 그래서이 도움이 또는하지 않을 경우 확실하지 - t이

무엇인지 알고도 아니다 나는 할 귀하의 목록이 큰 경우 메모리 문제.

+0

답장을 보내 주셔서 감사합니다. 그것은 나를 위해 일하지 않습니다. 내가 변경할 때 'cell = (ListingCell) tableView.DequeueReusableCell (식별자) 'to'cell = (ListingCell) tableView.DequeueReusableCell (identifier, indexPath) '응용 프로그램에서 ivalid 인수 오류가 발생했습니다. 나는 이것을 무시하고 'var views = NSBundle.MainBundle.LoadNib ("ListingCell", cell, null)'을 var view = NSBundle.MainBundle.LoadNib ("ListingCell", 셀, null)로 변경하고 다음 줄을 주석 처리합니다. 이제 응용 프로그램이 실행 시간에 'LocatoinLbl'과 같은 내 목록 객체에 오류가 발생합니다. –

+0

이미지 추가 및 메모리 오류에 관해서. 나는 get cell method에서 신경 써야했다. xamarin lazy table 예제를 기반으로합니다. –

+0

아마도 'LoadNib'메서드에서 사용하는 'nibName'매개 변수 때문일 수 있습니다. 그냥 내 사용자 지정 셀 클래스를 사용합니다. 하지만이 질문에 보이는 것입니다 http://stackoverflow.com/questions/7184206/loading-custom-table-view-cells-from-nib-files?rq=1 대답은이게 다른 일이라고 말하고 있습니다. 'nibName'에 대해 내가 틀렸어? –

관련 문제