0

私は最近 iPhone の開発に取り掛かりましたが、とても気に入っています。しかし、私はここ数時間、テーブル ビューに苦労してきました。より具体的には、テーブル ビューにカスタムの高さを与え、その上にナビゲーション バーを追加しました。

Interface Builder で、Table View と Navigation Bar を iPhone の「画面」にドラッグしました。次に、それらをコンセントとして配線しました。

xib ファイルの MainScreen.h:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>


@interface MainScreen : UIViewController 
{
    UINavigationBar *_nbMainScreen;
    UITableView *_tblMainScreen;
}

@property (retain, nonatomic) IBOutlet UINavigationBar *nbMainScreen;
@property (nonatomic, retain) IBOutlet UITableView *tblMainScreen;

@end

テーブル データ用に別の C# クラスを作成しました。

GenericTable.cs :

using System;
using System.Collections.Generic;
using System.IO;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace TestProject
{
    public class GenericTable : UITableViewSource
    {
        protected string[] tableItems;
        protected string cellIdentifier = "TableCell";

        public GenericTable (string[] items)
        {
            tableItems = items;
        }


        public override int NumberOfSections (UITableView tableView)
        {
            return 1;
        }


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


        public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
            string item = tableItems[indexPath.Row];

            //---- if there are no cells to reuse, create a new one
        if (cell == null)
        { 
                     cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier); }

                 cell.TextLabel.Text = item;

                 return cell;
        }
    }
}

MainScreen.cs :

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

namespace TestProject
{
public partial class MainScreen : UIViewController
{
    static bool UserInterfaceIdiomIsPhone {
        get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
    }

    public MainScreen ()
        : base (UserInterfaceIdiomIsPhone ? "MainScreen_iPhone" : "MainScreen_iPad", null)
    {
    }

    public override void DidReceiveMemoryWarning ()
    {
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning ();

        // Release any cached data, images, etc that aren't in use.
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        tblMainScreen = new UITableView(View.Bounds);
        tblMainScreen.AutoresizingMask = UIViewAutoresizing.All;
        CreateTableItems();
        Add (tblMainScreen);




        // Perform any additional setup after loading the view, typically from a nib.
    }


    protected void CreateTableItems ()
    {
        List<string> tableItems = new List<string> ();
        tableItems.Add ("Dog");
        tableItems.Add ("Cat");
        tableItems.Add ("Plane");
        tableItems.Add ("Phone");
        tableItems.Add ("Baloon");
        tblMainScreen.Source = new GenericTable(tableItems.ToArray());
    }
}

}

これは、複数のフォーラムやチュートリアル サイトで見つけた一般的な戦略ですが、それらはすべてフルスクリーンのテーブル ビューを使用しています。現在、私のテーブルは正しく入力されていますが、フォーラムの投稿と同様に、画面全体を占めています。IB でテーブルのサイズ/位置を変更しても、全画面表示のままで、ナビゲーション バーが表示されません。

前もって感謝します!

4

1 に答える 1

0

Interface Builder で、UIViewController が選択されているときに TopBar プロパティを変更します。

小さな「盾のような」エンブレムが付いたパネルにあるはずです。

その後、AppDelegate ファイルを以下にリストしたコードのようなものに変更します。

ここに画像の説明を入力

        MainScreen controller;
        UINavigationController navcontroller;

        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {

            // create a new window instance based on the screen size
            window = new UIWindow (UIScreen.MainScreen.Bounds);
            controller = new MainScreen ();

            var initialControllers = new List<UIViewController>();
            initialControllers.Add (controller);

            navcontroller = new UINavigationController ();
            navcontroller.ViewControllers = initialControllers.ToArray ();
            window.RootViewController = navcontroller;
            window.MakeKeyAndVisible ();
            return true;
        }
于 2013-10-02T00:49:29.723 に答える