Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-01-2011, 11:05 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 2
iambounty is on a distinguished road
Smile NSMutableArray addObject from SecondViewController expected ':' before '.'

Hi Everyone,
I was wondering if somebody out there would be as kind to help me out with an annoying little problem. I have looked around for a solution but I have had no luck.

What im trying to do is make a new entry to an NSMutable array from another view controller.


My array is as follows:
BookmarksViewController.h
#import <UIKit/UIKit.h>

@interface BookmarksViewController : UITableViewController {
NSMutableArray *bookmarksArray;
}

@property (nonatomic, retain) NSMutableArray *bookmarksArray;

@end


BookmarksViewController.m
@synthesize bookmarksArray;
- (void)viewDidLoad {
bookmarksArray = [[NSMutableArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"Mac Book Pro",nil];
[super viewDidLoad];
}
- (void)dealloc {
[bookmarksArray release];
[super dealloc];
}


Now I try to add an entry to my array from another view controller:

Ch01GettingStarted.m

#import "Ch01GettingStarted.h"
#import "BookmarksViewController.h"

@implementation Ch01GettingStarted

-(IBAction) pushChap01Bookmark: (id)sender{
[BookmarksViewController.bookmarksArray addObject:@"String"];
}


Now when I do this i get an "expected ':' before '.' error".

It doesn't have a problem when I use '[bookmarksArray addObject:@"String"];' from within the implementation file containing the array. Although what I want to do is add the string from another view controller when a command button is pressed.

I noticed that the following person is having the same problem:
http://www.iphonedevsdk.com/forum/ip...ple-views.html

Any help anyone could provide would be much appreciated as this is really bugging me.

Thank You
Carl
iambounty is offline   Reply With Quote
Old 01-02-2011, 01:58 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Cleveland, Ohio
Posts: 26
Panther is on a distinguished road
Default

The problem is this
Code:
[BookmarksViewController.bookmarksArray addObject:@"String"];
BookmarksViewController isn't an object- it's a type of object. You need to create an instance of BookmarksViewController, then you can get and work with its array.
Code:
BookmarksViewController *bookmarksViewController = [[BookmarksViewController alloc] init];
[bookmarksViewController.bookmarksArray addObject:@"String"];
Panther is offline   Reply With Quote
Old 01-02-2011, 09:04 PM   #3 (permalink)
iOS Programming God Mode
 
iOS IDDQD's Avatar
 
Join Date: Jan 2011
Location: Kansas
Posts: 29
iOS IDDQD is on a distinguished road
Default

Quote:
Originally Posted by Panther View Post
The problem is this
Code:
[BookmarksViewController.bookmarksArray addObject:@"String"];
BookmarksViewController isn't an object- it's a type of object. You need to create an instance of BookmarksViewController, then you can get and work with its array.
Code:
BookmarksViewController *bookmarksViewController = [[BookmarksViewController alloc] init];
[bookmarksViewController.bookmarksArray addObject:@"String"];

That isn't correct. In that case you'd be creating a new instance of a BookmarksViewController. I'm taking the guess that you need to use an existing instance of BookmarksViewController, by the way that you worded your question: adding something to an array from a "second view controller."

You need to pass the instance pointer to your second view controller first, then use the second line in the reply above. Ignore the first line with the [[alloc] init];
__________________
iOS IDDQD: God mode for iOS Development!
Father of Kill Stats XD, the premiere stat keeping application for iOS, tracking all of your fps games. Kill Stats XD on the App Store
iOS IDDQD is offline   Reply With Quote
Reply

Bookmarks

Tags
addobject, expected ':' before '.', nsmutablearray

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 362
7 members and 355 guests
blueorb, fredidf, iAppDeveloper, iGamesDev, mottdog, sacha1996, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0