2012-03-07 7 views
2

今、私はストーリーボードにテーブルビューコントローラにプッシュするUIButton設定を持っています。これは期待どおりに動作しています。私がしようとしているのは、UIButtonが押されたときにxmlファイルを読み込み、まだテーブルビューコントローラに移動させることです。Xcode 4 UIButtonをテーブルビューコントローラに移動

どうすればいいですか?私は既にXMLのコードを持っています。それはコードがどこに行き、新しいViewControllerサブクラスの.hと.mファイルをどのように追加するのかの問題です。UIViewController。ストーリーボードで作成したUIButtonにこれらのファイルをリンクするにはどうすればよいですか?

答えて

5

ボタン接続を新しいビューにドラッグし、プッシュまたはモーダルの代わりにカスタムセグを選択します。

enter image description here

変更「mySegueClass1」や、これまで何あなたがそれを呼び出すしたいと、新しいカスタムセグエのクラス。

enter image description here

あなただけのカスタムセグエに割り当てられたのと同じ名前で、新しいObjective-Cのクラスを作成します。

enter image description here その後、あなたのmySegueClass1.mファイル内の次のコードを追加し、-(void)perform

-(void)perform{ 
    UIViewController *dst = [self destinationViewController]; 
    UIViewController *src = [self sourceViewController]; 
    [dst viewWillAppear:NO]; 
    [dst viewDidAppear:NO]; 


    [src.view addSubview:dst.view]; 

    CGRect original = dst.view.frame; 

    dst.view.frame = CGRectMake(dst.view.frame.origin.x, 0-dst.view.frame.size.height, dst.view.frame.size.width, dst.view.frame.size.height); 

    [UIView beginAnimations:nil context:nil]; 
    dst.view.frame = CGRectMake(original.origin.x, original.origin.y, original.size.height, original.size.width); 
    [UIView commitAnimations]; 

    [self performSelector:@selector(animationDone:) withObject:dst afterDelay:0.2f]; 
} 
- (void)animationDone:(id)vc{ 
    UIViewController *dst = (UIViewController*)vc; 
    UINavigationController *nav = [[self sourceViewController] navigationController]; 
    [nav popViewControllerAnimated:NO]; 
    [nav pushViewController:dst animated:NO]; 
} 
+0

私は今日このコードを実装する機会がありました(妻は赤ちゃんでした)。このような徹底的な対応をするのに十分な時間をとっていただきありがとうございます。 – cmutchler

+0

何も問題なく、おめでとうございます! –

3

に何をしたい、これまでアクションを追加する方法があります:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    //You can access the tableviewcontroller using segue.destinationViewController 
    //Maybe you want to set your model here. 
} 

と呼ばれていますセグを作る前にここで必要な設定をすべて行うことができます。このメソッドは、segueを受け取るコントローラではなくsegueを実行するコントローラの内部に配置する必要があります。 (実際、おそらくxcodeは既にあなたのためにそのコードを置いています)。

関連する問題