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

  • SEARCH
  • Home
  • 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 6046113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:12:04+00:00 2026-05-23T07:12:04+00:00

i am trying to write a UIToolbar subclass and am having issues. This is

  • 0

i am trying to write a UIToolbar subclass and am having issues. This is the first time i have truly tried to sub class anything so forgive me if it is something stupid. I cant work out how to return an instance of the class from within its self.
eg

keyboardToolBar *toolbar;
@property (nonatomic, retain) keyboardToolBar *toolbar;
toolbar = [[keyboardToolBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)
-(keyboardToolBar*)initWithFrame:(CGRect)frame{

keyboardToolBar *keyboard = [[keyboardToolBar alloc] initWithFrame:frame];<--how can i do this
//do stuff with keyboard
return keyboard;
}

I assume the above will be stuck in an endless loop of calling init which calls init and so on, so how do you return an instance of a class from within its own init method or is there a better way of doing this.

thanks

darc

  • 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-05-23T07:12:04+00:00Added an answer on May 23, 2026 at 7:12 am

    There are many things that are not clear here. Are you trying to create convenience method? in which case you should call it keyboardToolbarWithFrame: and implement it like

    + (id)keyboardToolbarWithFrame:(CGRect)frame {
        return [[[self alloc] initWithFrame:frame] autorelease];
    }
    

    Note the + sign indicating that it is a class method. This will give you an autoreleased instance of your class.

    Now if you were just trying to class its super class for necessary initialization, you can just remove the method. It will call the super class’ initWithFrame: method. But usually your own implementation will be something like this,

    - (id)initWithFrame:(CGRect)frame {
        self = [super init];
        if ( self ) {
            // Do your class initializations here.
        }
    
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write this small program to help me in my Stats class, everything
Trying to write a handler for a packet sniffer. I'm having issues with casting
Im trying to write a single activity app, extending ListActivity. I have a class
Trying to write my first generic class in C#: public class HighScoreList<ScoreType> where ScoreType
I'm trying write a query to find records which don't have a matching record
Im trying to write something to get my images to show correctly. I have
Trying to write a trivial application, But I have stuck into one of the
Im' trying to write a class BrokenObjectException class derivated from Exception. But in Eclipse
I referred to this article http://www.codeproject.com/KB/security/DotNetCrypto.aspx and I am trying write an encrypted string
Trying to write better JavaScript, woohoo! First step for me: YUILoader dependency loader so

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.