[英]error: expected expression before 'createCharacter'
所以我正在使用presentmodalviewcontroller更改ipad应用程序中的活动视图。 但是,当我尝试使用语句[self presentModalViewController:createCharacter animated:NO];
更改它时[self presentModalViewController:createCharacter animated:NO];
在由按钮触发的动作中。 但是我得到一个错误,说'createCharacter'之前期望的表达式。 createCharacter是我创建的自定义视图控制器。有人知道我在做什么错吗? 如果您需要更多相关代码,请告诉我,谢谢
其他相关代码:
#import "createCharacter.h";
-(IBAction) buildCharacter{
[self presentModalViewController:createCharacter animated:NO];
}
createCharacter.h:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface createCharacter : UIViewController {
IBOutlet UIView *view;
}
@end
我很想看看一些代码,如果没有它,也许这个建议是错误的,但是...根据我的经验,我一直将IBActions与单个参数一起使用,并且该参数一直是发送者,所以像是将按钮按下按钮
-(IBAction) presentNewController:(id)sender`
发送者是被按下的按钮。
如果您使用类似的方法来检测IB中的按钮按下,那么在代码中您会想要的是:
// In your current view controller, the target where you wired up the button
-(IBAction) presentNewController:(id)sender
{
if([sender isEqual:<whatever button you expect>])
{
CustomController *con = [[[CustomController alloc] init] autorelease];
[selfpresentModalViewController:con animated:YES];
}
}
您需要先分配和初始化createCharacter,然后才能将其推入视图。
假设createCharacter是一个视图控制器:
createCharacter *customView = [[createCharacter alloc] initWithNibName:yourNibNameORnil bundle:yourBundleNameORnil];
[self presentModalViewController:customView animated:YES];
[customView release];
看来您正在将一个类发送到presentModalViewController:animated:。 您需要按照Rog所示初始化类。 至于圣雄的回答,我不知道为什么要摆脱你的错误。 对于OS X,他是正确的,但对于iOS,则不需要此参数。
遵循Rog的示例后,仍然有一些原因可能仍然导致错误:
您的初始化代码不正确。 在Rog的示例中,他使用了默认参数名称。 您应该将yourNibNameORnil
更改为NIB文件的名称,如果不使用NIB, yourNibNameORnil
其更改为nil。 假设NIB位于应用程序包中,您还应该将yourBundleNameORnil
更改为nil。 这是一个示例,假设NIB位于应用程序中,并且名为createCharacter.xib:
createCharacter * customView = [[[createCharacter alloc] initWithNibName:@“ createCharacter” bundle:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.