2012-03-25 65 views
0

我已经在一个独立的类中创建了一个自定义的uitableviewcell,并在uitableview中的viewcontroller中使用它。现在我想通过点击我的自定义uitableviewcell中的按钮来导航用户到另一个页面。有人可以帮帮我吗?定制uitableviewcell中的导航

以下是我的按钮点击动作的代码中的UITableViewCell:

-(IBAction)followUser:(id)sender { 
    NSLog(@"memberid %d",self.memberid); 
    profileViewController *profile = [[profileViewController alloc] init]; 
    [((UIViewController*) sender).navigationController pushViewController:profile animated:FALSE]; 

} 

但它崩溃。

回答

0

[profileViewController alloc]是错误的。你想分配对象的实际类,而不是实例变量。

1

您的操作方法'followUser:'的发件人参数指的是调用该方法的控件。这可能是一个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子类的名称。

+0

sender实际上是我添加了tableview的视图控制器。 tableview有自定义的tableview单元格,这些单元格的这个按钮就是我的代码被调用的那个按钮。所以你的答案不会成立,因为UIButton不存在于UIViewcontroller上,而是存在于UITableviewCell上。 – pankaj 2012-04-03 09:25:43