检测UIMyView何时关闭

时间:2013-12-03 06:53:25

标签: ios

我想知道我是否以正确的方式做到了。我有我的类UIMyView,我添加到我的主UIView。在那个UIMyView我使用NSTimer做一些事情,毕竟我调用removeFromSuperView方法返回主UIView。我想注意我的UIMyView何时关闭。我使用NSNotificationCenter来做这件事,但也许还有其他更好的方法吗?

编辑: 好的,但我想你,你不理解我。使用setHidden或containsObject我们需要执行此操作,例如puttin it click Button或类似的东西。我想做的是检查何时关闭UIMyView而没有任何用户交互。

4 个答案:

答案 0 :(得分:1)

尝试这个。可能这对你有帮助

BOOL hasMapView = [self.contentView.subviews containsObject:self.mapView];
UIView *fromView, *toView;
if (hasMapView)
{
    [btnMode setImage:[UIImage imageNamed:@"map-mode.png"] forState:UIControlStateNormal];

    fromView = self.mapView;
    toView = self.tblVideo;
    [self.tblVideo reloadData];
}
else
{
    fromView = self.tblVideo;
    toView = self.mapView;

    [btnMode setImage:[UIImage imageNamed:@"list-mode.png"] forState:UIControlStateNormal];
    [self reloadPins];
}

答案 1 :(得分:0)

使用它而不是使用removeFromSuperView

[urViewnm setHidden:YES];

答案 2 :(得分:0)

检测视图是否已关闭

BOOL isViewActive = [self.view.subviews containsObject:UIMyView];

答案 3 :(得分:0)

使用协议可以实现:

1.在CustomViewController.h中创建协议

 @protocol CustomViewControllerDelegate <NSObject>

- (void) didCustomViewControllerRemove:(id)sender;

@end

@interface CustomViewController : UIViewController

@property (retain) id <NSObject, CustomViewControllerDelegate> delegate;

@end
  1. 在CustomViewController.m中实现协议
  2.   #import "CustomViewController.h"
    
        @implementation CustomViewController
    
      - (IBAction)cancelBtnPressed:(id)sender {    
        [_delegate didCustomViewControllerRemove:self];
    
      }
    
    1. UIMyView.h
    2.   

      #import“CustomViewController.h”

           

      @interface UIMyView:UIViewController'&lt;'CustomViewControllerDelegate'&gt;'

           

      {}

      1. 使用委托方法UIMyView.m
      2.  - (void) addCustomViewControllerMethod {
        
          CustomViewController *obj = [CustomViewController alloc]
         initWithNibName:@"CustomViewController" bundle:nil];
        
          [self.view addSubView: obj];
        
          obj.delegate =self; 
        
         }      
          - (void)didCustomViewControllerRemove:(id)sender {
        
                 [self dismissViewControllerAnimated:YES completion:nil];      
         }