1

我有一个 UIView 子类,我在其中覆盖了多点触控处理方法。我的问题是,如果我在该视图上使用给定的触摸执行计算,它会破坏模型视图控制器设计模式吗?计算后,我必须隐藏视图、打印结果并更新我的核心数据模型。我对此感到困惑。

编辑:

一些代码。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // getting all the touches in the given gesture sequence
    NSSet *allTouches = [event allTouches];

    // checking taps count
    if ([allTouches count] == 3)
    {
        // here I print the results and do the calculations
        [self validateGestureSequenceWithTouches:allTouches];
    }

    // cleaning the view
    NSArray *subviews = [self subviews];
    for (UIView *view in subviews) {
       if (![view isKindOfClass:[UINavigationBar class]])
           [view removeFromSuperview];
    }
}
4

1 回答 1

2

为了遵守 MVC 准则,您的业务级计算需要在模型层中进行。但是,并非所有计算都符合“业务计算”的条件:通常您必须执行计算才能决定 UI 事务,例如

  • 单个 UI 元素的可见性
  • 单个 ui 元素的大小,
  • 触摸的位置和方向,

等等。如果您的计算属于商业类型,那么您应该将其移至模型中。否则,最好将其保留在视图或控制器中。

于 2013-03-29T00:57:40.373 回答