Xamarin.comの例から基本的なM.T. Dialog
アプリを構築できますが、実際のアプリケーションを構築するにはどうすればよいでしょうか?
あなたは:
1) そこから 1 つDialogViewController
のツリーを作成するview/RootElement
か、または、
2) DialogViewController
for every ビューを作成し、必要に応じて使用しUINavigationController
てプッシュしますか?
あなたの答えに応じて、より良い応答はどのようにですか? サンプルタスクアプリを作成したので、テーブルに要素を追加することを理解しています。クリックして編集用の「次の」ビューに移動しますが、非編集用にクリックするにはどうすればよいですか? 答えが 1 の場合、ボタンをクリックして次のビューに移動する方法は?
改訂:
おそらく唯一の正解はありませんが、私が思いついたものはうまくいくようです。上記の番号 2 が選択されたものです。以下は、現在存在するコードの例です。でナビゲーション コントローラーを作成し、AppDelegate
次のようにアプリケーション全体でアクセスできるようにしました。
public partial class AppDelegate : UIApplicationDelegate
{
public UIWindow window { get; private set; }
//< There's a Window property/field which we chose not to bother with
public static AppDelegate Current { get; private set; }
public UINavigationController NavController { get; private set; }
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Current = this;
window = new UIWindow (UIScreen.MainScreen.Bounds);
NavController = new UINavigationController();
// See About Controller below
DialogViewController about = new AboutController();
NavController.PushViewController(about, true);
window.RootViewController = NavController;
window.MakeKeyAndVisible ();
return true;
}
}
次に、すべてDialog
の構造は次のようになります。
public class AboutController : DialogViewController
{
public delegate void D(AboutController dvc);
public event D ViewLoaded = delegate { };
static About about;
public AboutController()
: base(about = new About())
{
Autorotate = true;
about.SetDialogViewController(this);
}
public override void LoadView()
{
base.LoadView();
ViewLoaded(this);
}
}
public class About : RootElement
{
static AboutModel about = AboutVM.About;
public About()
: base(about.Title)
{
string[] message = about.Text.Split(...);
Add(new Section(){
new AboutMessage(message[0]),
new About_Image(about),
new AboutMessage(message[1]),
});
}
internal void SetDialogViewController(AboutController dvc)
{
var next = new UIBarButtonItem(UIBarButtonSystemItem.Play);
dvc.NavigationItem.RightBarButtonItem = next;
dvc.ViewLoaded += new AboutController.D(dvc_ViewLoaded);
next.Clicked += new System.EventHandler(next_Clicked);
}
void next_Clicked(object sender, System.EventArgs e)
{
// Load next controller
AppDelegate.Current.NavController.PushViewController(new IssuesController(), true);
}
void dvc_ViewLoaded(AboutController dvc)
{
// Swipe location: https://gist.github.com/2884348
dvc.View.Swipe(UISwipeGestureRecognizerDirection.Left).Event +=
delegate { next_Clicked(null, null); };
}
}
必要に応じて要素のサブクラスを作成します。
public class About_Image : Element, IElementSizing
{
static NSString skey = new NSString("About_Image");
AboutModel about;
UIImage image;
public About_Image(AboutModel about)
: base(string.Empty)
{
this.about = about;
FileInfo imageFile = App.LibraryFile(about.Image ?? "filler.png");
if (imageFile.Exists)
{
float size = 240;
image = UIImage.FromFile(imageFile.FullName);
var resizer = new ImageResizer(image);
resizer.Resize(size, size);
image = resizer.ModifiedImage;
}
}
public override UITableViewCell GetCell(UITableView tv)
{
var cell = tv.DequeueReusableCell(skey);
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, skey)
{
SelectionStyle = UITableViewCellSelectionStyle.None,
Accessory = UITableViewCellAccessory.None,
};
}
if (null != image)
{
cell.ImageView.ContentMode = UIViewContentMode.Center;
cell.ImageView.Image = image;
}
return cell;
}
public float GetHeight(UITableView tableView, NSIndexPath indexPath)
{
float height = 100;
if (null != image)
height = image.Size.Height;
return height;
}
public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath indexPath)
{
//base.Selected(dvc, tableView, path);
tableView.DeselectRow(indexPath, true);
}
}
@ミケル
ワークフローの現在のアイデアは、Default.png の jpg で始まり、最初のビューにフェードインし、フロー コントロール ボタンがメイン アプリに移動するアプリです。の前に作業していたこのビューはM.T.D. (MonoTouch.Dialog)
、画像を含むテキスト行のテーブルです。各行をクリックすると、行/テキストをより詳細に表示する別のビューに移動します。
アプリはアプリ内購入もサポートしているため、クライアントが製品をさらに購入したい場合は、別のビューに切り替えて購入を処理します。に乗り換えた一番の理由はこの部分で、ぴったりM.T.D.
だと思ったからです。M.T.D.
最後に、購入などを再度有効にするための設定ビューがあります。
PS アプリが最小化されていないことをどのように知ることができますか? フェードイン画像をもう一度お見せしたいと思います。