こんにちは私はプログラムでボタンを作成し、ボタンを別のビューに接続しますが、ストーリーボードにprepareForSegueメソッドを使用する必要があるというセグエの問題が発生しましたが、インターネットにサンプルがどのようにあるかわかりませんが、それを使用するとエラーが発生しますサンプル、助けてくれませんか
前もって感謝します!
これが私のコードです
ボタンの作成
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor colorWithRed: 201.0/255.0 green: 201.0/255.0 blue:201.0/255.0 alpha: 1.0];
button.tag = currentTag;
currentTag++;
[button.layer setBorderColor: [[UIColor blackColor] CGColor]];
[button.layer setBorderWidth: 1.0];
[button setTitle:[NSString stringWithFormat:@"%d",currentTag] forState:UIControlStateNormal];
button.frame = CGRectMake(80*x, 32*y, 80, 32);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonView addSubview: button];
ボタンのアクション
-(void)buttonPressed:(UIButton *)button
{
NSLog(@"button %u -- frame: %@", button.tag, NSStringFromCGRect(button.frame));
WeekView *crtObj=[[WeekView alloc]initWithNibName:@"WeekView" bundle:nil];
[self.navigationController pushViewController:crtObj animated:YES];
[crtObj release];
}
セグエの準備
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"WeekView"]) {
// Get reference to the destination view controller
WeekView *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object]; //// I don't know what should I write instead of object
}}
エラー
編集2:****警告があります:
ビューコントローラから直接開始されたセグエには、-[UIViewController PerformSegueWithIdentifier:sender:]で使用する識別子が必要です。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"WeekView"]) {
// Get reference to the destination view controller
// WeekView *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
// [vc setMyObjectHere:object];
[segue.destinationViewController setTitle:@"WeekView"];
}}