ボタン付きのViewControllerがナビゲーションコントローラにあると仮定します-おそらくルートにあります...
あなたがすることは、あなたのボタンのそれぞれにターゲットを追加することです、コードでこれはあなたの方法addTarget:action:forControlEvents:
で行うことができますUIButton
例えば:
[myBtn addTarget:self action:@selector(tappedButton:) forControlEvents:UIControlEventTouchUpInside];
メソッドtappedButtonは、タップされたボタンとともにメッセージが表示されます。
- (void)tappedButton:(UIButton*)sender{
// exploit the button
}
このメソッド内で、ボタンのタイトルを取得できます-myBtn.titleLabel.text
UIViewController
次に、新しいView Controllerを作成できます(物事を単純に保ち、と呼ばれる独自のサブクラスがあるとしましょうMySimpleViewController
。
このクラスにはcameFrom
、ボタンのタイトルを設定できるプロパティがあり、viewDidLoad
のではMySimpleViewController
、のプロパティ値を取得しますcameFrom
。これは、メソッドの実装である可能性があります。
- (void)tappedButton:(UIButton*)sender{
MySimpleViewController *detail = [[MySimpleViewController alloc] init];
detail.cameFrom = sender.titleLabel.text;
[self.navigationController pushViewController:detail
animated:YES];
[detail release];
}
したがって、でMySimpleViewController's
viewDidLoad
、を作成しUILabel
、textプロパティにの値をself.cameFrom
指定して、を使用してビューに追加します。addSubview: