简体   繁体   English

在 Xcode 中,错误显示“活动”未声明

[英]In Xcode an error says 'activities' undeclared

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:我的代码如下: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"在 [activities count] 和 [activities release] 旁边,它指出错误“'activities' undeclared”

InstaTwitViewController.h: 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 . actvities应该是activities ,带有i

You should be more careful while coding, and reading your own code...在编码和阅读自己的代码时,您应该更加小心......

EDIT END编辑结束

Apparently, you haven't declared the activities variable.显然,您还没有声明activities变量。 That's why XCode says it's undeclared...这就是为什么 XCode 说它是未申报的……

I guess it should be an NSArray... You need to declare the variable in your class interface (the header file).我想它应该是一个 NSArray... 您需要在 class 接口(header 文件)中声明变量。

Something like:就像是:

@interface InstaTwitViewController: UIViewController
{
    NSArray * activities;
}
@end

Then, in your implementation, you need to allocate it, for instance in the init method:然后,在您的实现中,您需要分配它,例如在 init 方法中:

- ( 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:并且不要忘记在 dealloc 方法中释放它:

- ( 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.去掉 viewDidLoad 方法前后的/**/代码,并在 your.h 文件中声明一个名为 activity 的 NSArray。

NSArray *activities;

EDIT---- As MacMade said, just fix the spelling mistake!编辑----正如麦克梅德所说,只需修复拼写错误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM