0

Monodevelop と monotouch に基づく xcode 4 で、iPhone アプリケーション用のカスタム テーブル セルを作成したいと考えています。この記事を見つけました:

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

この 2 つの記事で、次のようなクラスを作成します。

[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そして、私は自分で定義したアウトレットを設計しました。次に、私のGetCell方法では、次のようなコードを使用しました。

    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;
        }

これで、アプリケーションは正常にビルドされますが、実行すると、デバッガーで次の行でエラーが発生します。

    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'

本当にこれは何のためにあるのかわかりません。削ると。ListingCellアプリケーションは、クラスのセル オブジェクトでエラーを起こします。インターネットで多くの検索を実行しましたが、解決策が見つかりませんでした。これについて何らかの考えを持っている体はありますか?

カスタムセルをプログラムで作成できることがわかりました。それは機能しますが、問題は、実行時にプログラムで難しいセルを作成するのが非常に難しいことです。このセルをexcodeで作成するのは簡単ですが、なぜ機能しないのかわかりません:-S

4

1 に答える 1

0

あなたが見ている問題が何であるかはよくわかりません。

ただし、iOS6 のみを使用している場合は、LoadNib コードを使用する代わりに、NIB を登録してテーブル セルをデキューするための新しい 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;
}

これは、あなたが言及した記事の 1 つに基づいています - http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html (免責事項 - 私が書きました!)


本当にこれが何のためにあるのかわからない

私もそうではありません-これが役立つかどうかはわかりません...


余談>あなたのAddImageToCellコードは私には間違ったにおいがします-リストが大きい場合、メモリの問題が発生する可能性があるようなにおいがします。

于 2013-02-22T09:08:27.317 に答える