如何使用realm.addNotificationBlock? [英] How to use realm.addNotificationBlock?

查看:164
本文介绍了如何使用realm.addNotificationBlock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在IOS应用中玩转游戏.

我尝试通过使用realm.addNotificationBlock重新加载tableView.但是我不知道如何实现这一点.有人可以帮我提供确切的代码示例吗?

谢谢

解决方案

您可以检查类引用以实现用于在RLMRealm中捕获更改的通知处理程序:问题中,您有一个测试用例(非主线程)使用addNotificationBlock.

希望这对您有所帮助.


更新

还要检查示例: RealmTableViewExample

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupUI];

    // Set realm notification block
    __weak typeof(self) weakSelf = self;
    self.notification = [RLMRealm.defaultRealm addNotificationBlock:^(NSString *note, RLMRealm *realm) {
        [weakSelf reloadData];
    }];
    [self reloadData];
}

- (void)reloadData
{
    self.array = [[DemoObject allObjects] arraySortedByProperty:@"date" ascending:YES];
    [self.tableView reloadData];
}

I am playing around with swift and realm in an IOS app.

I try to reload tableView by using realm.addNotificationBlock. But I don't know how to implement this. Can someone help me with exact code example?

Thanks

解决方案

You can check the class reference to implement the notification handler that catch the changes in the RLMRealm: http://realm.io/docs/cocoa/0.80.0/api/Classes/RLMRealm.html

In this issue you have a test case (non main thread) using the addNotificationBlock.

I hope this may help you.


UPDATE

Check also the examples: RealmTableViewExample

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupUI];

    // Set realm notification block
    __weak typeof(self) weakSelf = self;
    self.notification = [RLMRealm.defaultRealm addNotificationBlock:^(NSString *note, RLMRealm *realm) {
        [weakSelf reloadData];
    }];
    [self reloadData];
}

- (void)reloadData
{
    self.array = [[DemoObject allObjects] arraySortedByProperty:@"date" ascending:YES];
    [self.tableView reloadData];
}

这篇关于如何使用realm.addNotificationBlock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆