我的屏幕不移动下一个屏幕按钮点击iOS?

我的屏幕不移动下一个屏幕按钮点击iOS?,ios,objective-c,Ios,Objective C,我想将一个屏幕移动到下一个屏幕,并为此编写代码,但在单击按钮时不会在下一个屏幕上移动。此代码中存在什么问题 smsDisplayViewController.h @interface smsDisplayViewController : UIViewController<UITextFieldDelegate> { UIButton *btncomment; } - (IBAction)btncomment:(id)sender; @property(strong,non

我想将一个屏幕移动到下一个屏幕,并为此编写代码,但在单击按钮时不会在下一个屏幕上移动。此代码中存在什么问题

smsDisplayViewController.h

@interface smsDisplayViewController : UIViewController<UITextFieldDelegate>
{

UIButton *btncomment;

}

- (IBAction)btncomment:(id)sender;


@property(strong,nonatomic)UIButton *btncomment;

@end


smsDisplayViewController.m

@implementation smsDisplayViewController
@synthesize smsdisplay,Id,btncomment;

- (IBAction)btncomment:(id)sender
{
    CommentScreenViewController *viewController = [[CommentScreenViewController alloc]
                                                   initWithNibName:@"CommentScreenViewController" bundle:nil];

    [self.navigationController pushViewController:viewController animated:YES];
    NSLog(@"btn press");
}

[btncomment addTarget:self action:@selector(btncomment:)
     forControlEvents:UIControlEventTouchUpInside];
我想将一个屏幕移动到下一个屏幕,并为此编写代码,但在单击按钮时不会在下一个屏幕上移动。此代码中存在什么问题

smsDisplayViewController.h

@interface smsDisplayViewController : UIViewController<UITextFieldDelegate>
{

UIButton *btncomment;

}

- (IBAction)btncomment:(id)sender;


@property(strong,nonatomic)UIButton *btncomment;

@end


smsDisplayViewController.m

@implementation smsDisplayViewController
@synthesize smsdisplay,Id,btncomment;

- (IBAction)btncomment:(id)sender
{
    CommentScreenViewController *viewController = [[CommentScreenViewController alloc]
                                                   initWithNibName:@"CommentScreenViewController" bundle:nil];

    [self.navigationController pushViewController:viewController animated:YES];
    NSLog(@"btn press");
}

[btncomment addTarget:self action:@selector(btncomment:)
     forControlEvents:UIControlEventTouchUpInside];
smsDisplayViewController.h
@接口smsDisplayViewController:UIViewController
{
UIButton*btncomment;
}
-(iAction)BTN建议:(id)发送方;
@属性(强,非原子)UIButton*Btnomment;
@结束
smsDisplayViewController.m
@smsDisplayViewController的实现
@合成SMS显示、Id、BTN注释;
-(iAction)BTN建议:(id)发送方
{
CommentScreenViewController*viewController=[[CommentScreenViewController alloc]
initWithNibName:@“CommentScreenViewController”捆绑包:nil];
[self.navigationController pushViewController:viewController动画:是];
NSLog(“btn新闻”);
}
[btncomment addTarget:自我操作:@选择器(btncomment:)
forControlEvents:UIControlEventTouchUpInside];
我想将一个屏幕移动到下一个屏幕,并为此编写代码,但单击按钮时不会在下一个屏幕上移动。 我想将一个屏幕移动到下一个屏幕,并对其进行编码,但它不会在单击按钮时移动到下一个屏幕。

我认为您自己不是导航控制器,因此属性

self.navigationController
返回零

如果需要,您可以使用情节提要在没有导航控制器的控制器之间切换,或以模式显示新控制器:

UIViewController *newViewController = [[UIViewController alloc] init];
[self presentViewController: newViewController animated: YES completion: nil];

如果不想使用NavigationController,请使用以下代码

- (IBAction)btncomment:(id)sender
{
   CommentScreenViewController *nextViewController = [[CommentScreenViewController alloc]  initWithNibName:@"CommentScreenViewController" bundle:nil]; 
   [self presentViewController:nextViewController animated: YES completion: nil];
}

您是否已验证self.navigationController不是nil?是,但它不工作。我在另一个屏幕上实现了相同的代码,它的工作区别在于我在那个里点击了单元格,在这里点击了单元格button@ChetanGharat,您的控制台是否记录了
@“btn press”
消息?否,也不显示任何消息self.navigationController为零,viewController为nil或btncomment方法未被调用。我在iAction方法中使用的是nib文件而不是故事板。您是否按照我告诉您的方式演示了控制器?然而,我认为您的btncomment方法可能永远不会被调用!您注意到控制台中的日志了吗?sry它也不工作可能会将一个nib文件移动到另一个,因为在本例中,我正在使用导航控制器执行此操作。当您单击按钮时,是否出现任何错误…?请准确地使用此代码并回答..它是否工作。。。UIButton*btncomment=[[UIButton alloc]initWithFrame:CGRectMake(5010010035)];[btncomment setTitle:@“下一个”状态:UIControlStateNormal];[btncomment addTarget:self action:@selector(btncomment)for ControlEvents:UIControlEventTouchUpInside];[self.view addSubView:btncomment]-(void)btncomment{CommentScreenViewController*nextViewController=[[CommentScreenViewController alloc]initWithNibName:@“CommentScreenViewController”捆绑包:nil];[self-presentViewController:nextViewController动画:是完成:nil];}让我们来看看。