在非结构体或联合体中请求成员视图

4
我在构建我的iPhone应用时遇到了这个错误: [CommuneSlider.view removeFromSuperview];中的请求成员视图不是结构体或联合体。 代码如下: - (void) CommuneSelected {
CommuneDetailsViewController *com = [[CommuneDetailsViewController alloc] initWithNibName:@"CommuneDetailsViewController" bundle:nil];

UINavigationController *navig = [[UINavigationController alloc] 
                               initWithRootViewController:com];
[self setCommuneDetails:(CommuneDetailsViewController *) navig];
[navig setNavigationBarHidden:YES];
[com release];
[navig release];


[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];

[CommuneSlider.view removeFromSuperview];
[self.window addSubview:[CommuneDetails view]];

[UIView commitAnimations];

}

need HELP

3个回答

1

好的,这是AzurGuideAppDelegate.h文件:

@class CommuneSliderController, AccueilViewController,CommuneDetailsViewController;

@interface AzurGuideAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    AccueilViewController *AccueilController;
    CommuneSliderController *CommuneSlider;
    CommuneDetailsViewController *CommuneDetails;
    UINavigationController *navigationControl;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet AccueilViewController *AccueilController;
@property (nonatomic, retain) IBOutlet CommuneSliderController *CommuneSlider;
@property (nonatomic, retain) IBOutlet CommuneDetailsViewController *CommuneDetails;


- (void) goBack;
- (void) goFront;
- (void) CommuneSelected;

@end

这里是AzurGuideAppDelegate.m文件,我在其中定义了我的方法:

#import "AzurGuideAppDelegate.h"
#import "AccueilViewController.h"


@implementation AzurGuideAppDelegate

@synthesize window;
@synthesize AccueilController;
@synthesize CommuneSlider;
@synthesize CommuneDetails;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch

    [window addSubview:AccueilController.view];
    [window makeKeyAndVisible];
}

- (void) CommuneSelected {

    CommuneDetailsViewController *com = [[CommuneDetailsViewController alloc] initWithNibName:@"CommuneDetailsViewController" bundle:nil];

    UINavigationController *navig = [[UINavigationController alloc] 
                                   initWithRootViewController:com];
    [self setCommuneDetails:(CommuneDetailsViewController *) navig];
    [navig setNavigationBarHidden:YES];
    [com release];
    [navig release];


    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.8];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
    [CommuneSlider.view removeFromSuperview];
    [self.window addSubview:[CommuneDetails view]];

    [UIView commitAnimations];
}

以及我的CommuneSliderController类:

#import "AzurGuideAppDelegate.h"
#import "CommuneSliderController.h"
#import "CoverFlowView.h"
#import "CoverViewController.h"

#define CVC_VIEW_TAG        999

@implementation CommuneSliderController


- (IBAction) goFront:(id) sender {
    AzurGuideAppDelegate *main = (AzurGuideAppDelegate *)[[UIApplication sharedApplication] delegate];
    [main goFront]; 
}

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor whiteColor];
    self.view = contentView;
    [contentView release];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    CoverViewController *cvc = [[CoverViewController alloc] init];
    cvc.view.tag = CVC_VIEW_TAG;
    [self.view addSubview:cvc.view];    
}

1
如果这是错误行:
request for member view in something not a structure or union on [CommuneSlider.view removeFromSuperview];
它似乎表明 CommuneSlider 没有 "view" 成员。变量的名称让我想到它是一个 UIControl,而不是 UIViewController 的子类(后者将具有视图属性)。
你确定你不想要像这样的东西吗:
[CommuneSliderController.view removeFromSuperview];

0
如果这是C++,我会说“有一个指向类的指针,你试图使用pClass.foo而不是pClass->foo”,或者你尝试访问的类型由于某些原因而未知。也许这对Objective-C也有帮助。

实际上,这是用Objective-C编写的,并且CommuneSlider是我在myAppDelegate中定义的属性。@synthesize CommuneSlider; @synthesize CommuneDetails; - james
那么,它是指针还是结构体/类?你看,我只在C++环境中见过这些错误,并且对Objective-C几乎没有经验。 - iksemyonov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接