Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:41:39+00:00 2026-06-06T00:41:39+00:00

Hi I create button programmatically and I connect my button to another view, but

  • 0

Hi I create button programmatically and I connect my button to another view, but I got segue problem
that I should use prepareForSegue method for storyboard but I don’t know how there ar esome sample to the internet but I will get error when I used that sample, would you please help me

Thanks in advance!

here is my code

Creating Button

 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];

Action for 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];


}

Prepare for segue

- (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
    }}

error

enter image description here

Edit 2:**** I have a warning :

Segues initiated directly from view controllers must have an identifier for use with -[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"];
    }}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:41:41+00:00Added an answer on June 6, 2026 at 12:41 am

    There are really two ways to push a view controller onto the navigation controller.

    1. The old way, all in code. That is what you did. You can completely forget about segues at this point.

    2. The new way: establish a Segue in Storyboard (push segue from one view controller to a new view controller, which you also define in Storyboard), give it an Identifier name and then use this code to push the view controller.

    .

    [self performSegueWithIdentifier:myIdentifyer sender:self];
    

    where self is the view controller. Now you can do the customizations in prepareForSegue:.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I create button, use a background image that changes on hover and on
I have to create a button programmatically, and set an image background at that
I create a button programmatically.......... button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown]; [button
I'm trying to create a UIButton programmatically. I have a button called addCash (which
I am using the split view template to create a simple split view that
I'm trying to create a button programmatically and make it visible. This is what
How can I create a back button of a navigation controller programmatically?
I am trying to create a Button in Windows phone 7 without making use
I want to make certain. Can I create for example button programmatically in viewDidLoad,
How can I programmatically create Enter button press in .NET WinForms? I want on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.