2013-12-07 45 views
0

我正面临一个小问题。我有一个有两个班级的桌子。使用UIViewcontroller作为根视图,并在里面我有一个孩子UITableViewCell。我定制了一个单元格,并在里面有按钮。连接和使用自定义单元格中的表格内的按钮

问题:我该如何连接和使用按钮?

我已经尝试了一些提到的东西和解决方法..但没有用。最后,我感到非常沮丧,以至于我试图将标签贴上标签并使用它的标签使其充当按钮,如果这甚至是可能的话。

1)我试图将按钮连接到根视图,但是它在构建时导致故事板错误。

2)我试着将按钮连接到UITableViewCell。它不错,但在我要的-(IBAction)btnclicked内使用的按钮,这是代码:

-(IBAction)btnclicked 
{ 
     profileViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"AnotherView"]; 
     [self presentViewController:second animated:YES completion:nil]; 
} 

当我使用这个代码,我得到这些错误信息

的方法中的第一行: 属性“故事板”的类型为“AnotherView”

第二线对象未找到: 为“OtherUsersCell”不可见@interface声明选择“presentViewController:第二动画:是完成:”

即时通讯使用上面的代码连接我的意见,而不是故事板segues。

任何帮助,将不胜感激。

+0

@staticVoidMan仍然没有我们。我得到同样的错误。感谢寿 – shadramon

回答

0

我发现它!这里就是我所做的,首先在这个方法:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath 

正如所看到的波纹管,我给我的按钮标签(在我的情况下,-16),并确定指向按钮时,是应该运行方法的选择录音,在我的情况下,方法名是ButtonClicked

UIButton *Button= (UIButton*)[self.view viewWithTag: -16]; 
Button.tag = -16; 
[Button addTarget:self action:@selector(ButtonClicked) forControlEvents:UIControlEventTouchUpInside]; 

下面是我的方法的代码:

-(void) ButtonClicked 
{ 
     buyViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"MyOtherView"]; 
     [self presentViewController:second animated:YES completion:nil]; 
} 

我与不同类型的对象所面临的同样的问题,到目前为止,所有的我使用的标签可以从属性检查器分配给视图中的任何对象。我跳这有助于任何面临同样问题的人。

相关问题