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 8271845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:56:51+00:00 2026-06-08T06:56:51+00:00

What I want: On the iPhone user enters few values and tap on save

  • 0

What I want:

On the iPhone user enters few values and tap on save button.
App should store the values in an instance of VehicleClass and add it to an NSMutableArray.

Hope you can help.

ViewController.h

#import <UIKit/UIKit.h>
#import "VehicleClass.h"

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *producerTextField;
@property (weak, nonatomic) IBOutlet UITextField *modelTextField;
@property (weak, nonatomic) IBOutlet UITextField *pYearTextField;
@property (weak, nonatomic) IBOutlet UITextField *priceTextField;

@property (weak, nonatomic) NSMutableArray *carArray;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;


- (IBAction)addCar:(id)sender;
- (IBAction)showCars:(id)sender;

@end

ViewController.m

@synthesize producerTextField, modelTextField, pYearTextField, priceTextField, carArray;

- (void)viewDidLoad
{
    [super viewDidLoad];

    carArray = [NSMutableArray array];
}

- (IBAction)addCar:(id)sender
{
    VehicleClass *newVehic = [[VehicleClass alloc]initWithProducer:producerTextField.text 
                                                          andModel:modelTextField.text
                                                          andPYear:producerTextField.text
                                                          andPrice:priceTextField.text];

    [carArray addObject:newVehic];
    if (carArray != nil) {
        statusLabel.text = @"Car saved to array.";
    }
    else {
        statusLabel.text = @"Error, check your code.";
    }
}

VehicleClass.h

#import <Foundation/Foundation.h>

@interface VehicleClass : NSObject

@property (weak, nonatomic) NSString *producer;
@property (weak, nonatomic) NSString *model;
@property (weak, nonatomic) NSString *pYear;
@property (weak, nonatomic) NSString *price;


-(id)initWithProducer:(NSString *)varProducer 
             andModel:(NSString *)varModel 
             andPYear:(NSString *)varPYear 
             andPrice:(NSString *)varPrice; 

@end

VehicleClass.m

#import "VehicleClass.h"

@implementation VehicleClass

@synthesize model, price,pYear,producer;


-(id)initWithProducer:(NSString *)varProducer 
             andModel:(NSString *)varModel 
             andPYear:(NSString *)varPYear 
             andPrice:(NSString *)varPrice
{
    self = [super init];
    if (self != nil) 
    {
        producer = varProducer;
        model = varModel;
        pYear = varPYear;
        price = varPYear;
    }
    return self;
}

@end

Maybe the problem has something to do with my init method?

  • 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-08T06:56:54+00:00Added an answer on June 8, 2026 at 6:56 am

    carArray is a weak property, it should be strong.

    Also: you should use self.carArray and not carArray. When you use carArray, you are using the underlying iVar and not the actual property. It will cause confusion later.

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

Sidebar

Related Questions

In my iphone app, I want the user to enter his email address. I
I want to implement a search feature in an iPhone app. Basically, the user
I want my iphone app automatically logs on to Facebook so that the user
In my iPhone App I want to implemented functionality as shown below user can
I want to achieve the following, if someone enters site with Android/iPhone user agent,
I want to upload pictures to the AWS s3 through the iPhone. Every user
I want my iPhone App to display a list of ALL Bluetooth Devices nearby
I want to create an iPhone app which makes calls to a web service.
I want to make an iPhone OS app for a Wordpress blog, and I'm
I want to create an iPhone/iPad applications using Corona SDK. But they should be

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.