【发布时间】:2014-09-01 23:16:31
【问题描述】:
我有一个使用外部显示器的应用程序。
我的 iPad 上有真实的表格视图,外部屏幕上有镜像的表格视图。
现在,我正在使用NSNotification center 通知外部视图上的表格它必须滚动,但滚动非常粗糙,视觉上不性感,有滞后。
如何提高它的性能?如何让它光滑性感?
是的,两个 TableView 的大小不同。
这是我的代码:
带有真实UITableView的控制器:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView == self.iboTable)
[[NSNotificationCenter defaultCenter] postNotificationName:@"remoteControlTableScrolled" object:scrollView];
}
以及外屏上的控制器:
- (void)TableScrolled:(NSNotification *) notification
{
UITableView *notificationTableView = notification.object;
if(notificationTableView.contentOffset.y>self.iboTable.contentSize.height - self.iboTable.bounds.size.height)
{
CGFloat yOffset = 0;
yOffset = self.iboTable.contentSize.height - self.iboTable.bounds.size.height;
[self.iboTable setContentOffset:CGPointMake(0, yOffset) animated:YES];
}
else if(notificationTableView.contentOffset.y + notificationTableView.frame.size.height == notificationTableView.contentSize.height)
{
[self.iboTable scrollRectToVisible:CGRectMake(0, self.iboTable.contentSize.height - self.iboTable.bounds.size.height, self.iboTable.bounds.size.width, self.iboTable.bounds.size.height) animated:YES];
}
else
{
[self.iboTable setContentOffset:CGPointMake(notificationTableView.contentOffset.x,notificationTableView.contentOffset.y)animated:YES];
}
}
【问题讨论】:
-
尝试使用块而不是 NSNotificationCenter
-
对不起,我不明白你对块的意思
-
我希望@jailani 建议使用委托或块来通知而不是 NSNotification
-
在 ios 中有 4 种通信方式 1.Delegates 2.Call Backs 3.NSNotification 4.KVO & KVC。
-
块就像c中的函数指针:您可以声明NSBlock VC2(来自真实表视图的控制器)并将其定义为VC1(外部视图控制器)。从 VC1 分配你的块并从 VC2 调用它。
标签: ios objective-c ipad uitableview uiscrollview