美文网首页
iOS-随笔记录

iOS-随笔记录

作者: 琦玉老师很强 | 来源:发表于2020-08-19 20:20 被阅读0次

代码相关

1.跳转到指定的控制器

1)跳转到指定的前面跳来的页面

UIViewController *target = nil;

for (UIViewController * controller in self.navigationController.viewControllers) { // 遍历
    
    if ([controller isKindOfClass:[controller1 class]]) {
        target = controller;
    }
    else if([controller isKindOfClass:[controller2 class]]) {
        target = controller;
    } else if([controller isKindOfClass:[controller3 class]]) {
        target = controller;
    }
}

if (target) {
    [self.navigationController popToViewController:target animated:YES]; // 跳转
}

2)跳转指定前面的没有跳过的页面
(因为没有跳转过,所以需要创建)

walletPage *homeVC = [[controller1 alloc] init];

UIViewController *target = nil;

for (UIViewController * controller in self.navigationController.viewControllers) { // 遍历
    if ([controller isKindOfClass:[homeVC class]]) { // 这里判断是否为你想要跳转的页面
        target = controller;
    }
}

if (target) {
    [self.navigationController popToViewController:target animated:YES]; // 跳转
}
2.获取当前活动的NavigationController
- (UINavigationController *)getNavigationController {
    UIResponder *responder = self;
    while (![responder isKindOfClass:[UINavigationController class]]) {
        responder = [responder nextResponder];
        if (nil == responder) {
            return nil;
        }
    }
    return (UINavigationController *)responder;
}
3.Block定义
// 直接定义
@property (nonatomic, copy) void(^block)(NSInteger);
// 方法中定义
block:(void(^) (NSInteger index))block;
// 其他定义
typedef void(^Block)(NSInteger index);

@property (nonatomic, copy) Block block;
4.NSNotificationCenter通知传参使用方法
// 发送通知(不带参数)
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"loadH5code" object:nil userInfo:nil]];

// 注册通知(不带参数)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadH5code) name:@"loadH5code" object:nil];

// 实现监听方法
- (void)loadH5code {
    // do something
}
// 发送通知(带参数)
NSDictionary *dict = @{@"key":@"value"};
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"loadH5code" object:nil userInfo:dict]];

// 注册通知(带参数)
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loadH5code:) name:@"loadH5code" object:nil];

// 实现监听方法
- (void)loadH5code:(NSNotification *)notification {
    NSString *loadPathStr = notification.userInfo[@"key"];
    
    if ([h5PathStr isEqualToString:@"value"]) {
        // do something
    }
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"loadH5code" object:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];

文章相关

1.状态栏的隐藏显示与状态栏样式的设置

iOS 状态栏的隐藏显示与状态栏样式的设置

2. NSNotificationCenter 通知

透彻理解 NSNotificationCenter 通知
iOS中通知中心NSNotificationCenter应用总结

3.UICollectionView 相关文章

UIcollectionView实现不规则排列的算法

4.NSDictionary深入理解

iOS NSDictionary除了NSString 类型外还有什么类型可以作为key

相关文章

网友评论

      本文标题:iOS-随笔记录

      本文链接:https://www.haomeiwen.com/subject/tcawdktx.html