2013-08-17 65 views
0

我有一个UITableView与五个costum UITableViewCells。 如果TableView滚动所有单元格应执行相同的方法。UITableView的子视图?

下面是代码:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView 
{ 
    if(self.newsViewTable == scrollView) { 
     for(int i = 1; i < [self.newsViewTable.subviews count]; i++) { 
      [[self.newsViewTable.subviews objectAtIndex:i] hideSocialMediaBar]; 
     } 
    } 
} 

但如果我scoll总会有一个错误!

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView hideSocialMediaBar]: unrecognized selector sent to instance 0x8a9ea90' 

我现在不是为什么错误处理UIImageView? 只有一个UITableView的直接子视图,这就是Cell! 有什么不对?为什么它是一个UIImageView?

+0

哪里是hideSocialMediaBar方法..?与什么情况你想罚款这种方法? –

+0

它解决了! :)不过谢谢! :) – MyJBMe

回答

0

self.newsViewTable.subviews返回子视图数组。该错误显示出来,因为当它到达子视图数组中的UIImageView时,您将调用其上的hideSocialMediaBar方法,并且它不响应该方法。

如果hideSocialMediaBar是你想对你的细胞做的事情,你需要在细胞上调用它。

在您的滚动视图方法中,调用[self.tableview visiblecells]将返回接收器中可见单元格的NSArray。

因此改变:

[[self.newsViewTable.subviews objectAtIndex:i] hideSocialMediaBar];

[[self.newsViewTable.visiblecells objectAtIndex:i] hideSocialMediaBar];

+0

我知道,这可能是,但UIImageView是在任何地方! 那么,我该如何更改NSIndexPath的.row? – MyJBMe

+0

我很困惑,你到底想要完成什么。当某人滚动你想'hideSocialMediaBar'?在每个细胞上?当它们停止滚动时应该回来吗? –

+0

不!单元格中有一个按钮,它调用showSocialMediaBar! 但是这是在细胞特定的类中调用的,所以我不知道它在哪个单元中被调用,所以我想隐藏在所有单元格中!当它停止时,它保持隐藏状态直到按钮被触摸! – MyJBMe