我在一个单独的类中创建了一个自定义uitableviewcell,并在uitableview的viewcontroller中使用了它。现在,我想在自定义uitableviewcell中单击按钮将用户导航到另一个页面。有人可以帮帮我吗?
以下是我在uitableviewcell中单击按钮时的操作代码:
-(IBAction)followUser:(id)sender {
NSLog(@"memberid %d",self.memberid);
profileViewController *profile = [[profileViewController alloc] init];
[((UIViewController*) sender).navigationController pushViewController:profile animated:FALSE];
}
但是它崩溃了。
最佳答案
动作方法'followUser:'的sender参数是指调用该方法的控件。这可能是一个UIButton。显然,UIButton没有'navigationController'属性。如果您的代码位于导航堆栈上的UIViewController子类中,则该子类具有'navigationController'属性,您可以通过该属性访问UINavigationController。尝试这个:
-(IBAction)followUser:(id)sender {
NSLog(@"memberid %d",self.memberid);
profileViewController *profile = [[profileViewController alloc] init];
[self.navigationController pushViewController:profile animated:FALSE];
[profile release];
}
@CodaFi'profileViewController alloc'没问题,如果那是他的UIViewController子类的名称。