Hello I'm new to developing and I was wondering if any of you pros would know how to fix this issue. My code is Below: InstaTwitViewController.m:
#import "InstaTwitViewController.h"
@implementation InstaTwitViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
activities = [[NSArray alloc] initWithObjects:@"sleeping",
@"eating", @"working", @"thinking", @"crying", @"begging",
@"leaving", @"shopping", @"hello worlding", nil];
feelings = [[NSArray alloc] initWithObjects: @"awesome",
@"sad", @"happy", @"ambivalent", @"nauseous", @"psyched",
@"confused", @"hopeful", @"anxious", nil];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[activities release];
[feelings release];
[super dealloc];
}
- (NSInteger)numberOfComponentsInPickerView: (UIPickerView *)
pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)
pickerViewnumberOfRowsInComponent :(NSInteger)component {
if (component == 0) {
return [activities count];
}
else {
return [feelings count];
}
}
@end
Next to [activities count] and [activities release] it states an error "'activities' undeclared"
InstaTwitViewController.h:
//
// InstaTwitViewController.h
// InstaTwit
//
// Created by John Bridge on 5/2/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface InstaTwitViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray* actvities;
NSArray* feelings;
}
@end
EDIT
You have a typo in your property declaration.
actvities
should be activities
, with an i
.
You should be more careful while coding, and reading your own code...
EDIT END
Apparently, you haven't declared the activities
variable. That's why XCode says it's undeclared...
I guess it should be an NSArray... You need to declare the variable in your class interface (the header file).
Something like:
@interface InstaTwitViewController: UIViewController
{
NSArray * activities;
}
@end
Then, in your implementation, you need to allocate it, for instance in the init method:
- ( id )initWithNibName: ( NSString * )nibNameOrNil bundle: ( NSBundle * )nibBundleOrNil
{
if( ( self = [ super initWithNibName: nibNameOrNil bundle: nibBundleOrNil ] ) )
{
activities = [ NSArray new ];
}
return self;
}
And don't forget to release it in the dealloc method:
- ( void )dealloc
{
[ activities release ];
[ super dealloc ];
}
Remove the /*
and */
code before and after the viewDidLoad method, and declare an NSArray called activities in your.h file.
NSArray *activities;
EDIT---- As MacMade said, just fix the spelling mistake!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.