小编pgb*_*pgb的帖子

绑定变量时的RxSwift初始值

我有以下代码:

import RxSwift
import RxCocoa

class ViewModel {

    var text = Variable<String>("")

    init() {
        text.value = "hello"
    }

}

class ViewController: UIViewController {
    @IBOutlet weak var textView: UITextView!
    @IBOutlet weak var counterLabel: UILabel!

    var viewModel = ViewModel()

    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        textView.rx.text
            .orEmpty
            .debug()
            .bind(to: viewModel.text)
            .disposed(by: disposeBag)
    }
}
Run Code Online (Sandbox Code Playgroud)

精结合工程(当我改变UITextView它正确地更新viewModel.然而,由于结合是单向的(或者让我明白了),在textView不与我在设定的值开始ViewModelinit方法.

我可以textView.text = viewModel.text.value在绑定之前做,但由于我正在使用RxSwift,我想了解这里的常用做法.

ios swift rx-swift

4
推荐指数
1
解决办法
2071
查看次数

理解Objective-c中的方法

例如,我们在tableview中使用此方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 16;
}
Run Code Online (Sandbox Code Playgroud)

我想知道我们不会在任何地方调用此方法,但应用程序读取此值是怎么回事?有很多这样的方法,我们没有打电话.

iphone methods objective-c

3
推荐指数
1
解决办法
1134
查看次数

UIPicker的高度

我一直试图改变pickerView的高度.我希望它显示一行而不是默认的五行.帮帮我

iphone objective-c

3
推荐指数
1
解决办法
933
查看次数

performSelectorInBackgroundThread和NSTimer

对于我正在开发的游戏,我从其中一个触摸处理程序中调用了一种昂贵的方法.为了使它更快,我决定使用performSelectorInBackgroundThread,所以而不是:

[gameModel processPendingNotifications];
Run Code Online (Sandbox Code Playgroud)

我切换到:

[gameModel  performSelectorInBackground:@selector(processPendingNotifications) withObject:nil];
Run Code Online (Sandbox Code Playgroud)

我遇到的第一个问题是processPendingNotifications没有NSRunLoop,所以我添加了它,就像这样:

- (void)processPendingNotifications {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [pendingNotificationsQueue makeObjectsPerformSelector:@selector(main)];
    [pendingNotificationsQueue removeAllObjects];
    [pool drain];
}
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.我的问题是从这个后台线程调用的一些方法创建了新NSTimer实例.这些情况最终没有解雇.我认为这是因为我所拥有的辅助线程没有(或正在结束它)NSRunLoop.我正在使用以下方式启动新计时器:

[NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(timerFired) userInfo:nil repeats:NO];
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 我是否在正确的道路上怀疑问题与NSRunLoop?有关?
  2. 有没有办法NSTimer从后台线程启动并将其附加到主线程NSRunLoop

iphone multithreading objective-c

2
推荐指数
1
解决办法
4667
查看次数

将文本分成单词问题PHP,复杂的问题

我试图将文本分成单词:

$delimiterList = array(" ", ".", "-", ",", ";", "_", ":",
           "!", "?", "/", "(", ")", "[", "]", "{", "}", "<", ">", "\r", "\n",
           '"');
$words = mb_split($delimiterList, $string);
Run Code Online (Sandbox Code Playgroud)

用字符串工作得很好,但我遇到了一些与数字有关的情况.

例如,如果我有文本"看看这个.我的分数是3.14,我很高兴." 现在阵列是

[0]=>Look,
[1]=>at,
[2]=>this,
[3]=>My,
[4]=>score,
[5]=>is,
[6]=>3,
[7]=>14,
[8]=>and, ....
Run Code Online (Sandbox Code Playgroud)

然后3.14分为3和14,这在我的情况下不应该发生.我的意思是点应分两个字符串而不是两个数字.应该是这样的:

[0]=>Look,
[1]=>at,
[2]=>this,
[3]=>My,
[4]=>score,
[5]=>is,
[6]=>3.14,
[7]=>and, ....
Run Code Online (Sandbox Code Playgroud)

但我不知道如何避免这种情况!

任何人都知道如何解决这个问题?

Thanx,Granit

php split

2
推荐指数
2
解决办法
5440
查看次数

CCSprite遵循一系列CGPoints

我正在使用Cocos2D开发一个线图绘制游戏,类似于Flight Control,Harbor Master和appstore中的其他人.

对于这个游戏,我需要一个CCSprite来跟随用户绘制的一条线.我根据我在和消息中得到的点存储了一系列CGPoint结构.我现在有一个问题,如何让我的精灵跟随他们.NSArraytouchesBegintouchesMoved

我有一个tick方法,以帧速率调用.在该tick方法中,基于精灵的速度和当前位置,我需要计算它的下一个位置.有没有标准的方法来实现这一目标?

我当前的方法是计算最后一个"参考点"和下一个参考点之间的线,并计算该线中的下一个点.我遇到的问题是精灵"转"(从一段线移动到另一段).

任何提示将不胜感激.

iphone cocos2d-iphone

2
推荐指数
1
解决办法
1860
查看次数

Objective-C:计算类别中对象的有效方法

我在一组类别中有一堆对象.我想知道每个类别有多少.

在另一种语言中,我会创建一个字典,然后遍历这些对象,为每个对象增加字典中的相应值.但是,因为我无法在Objective-C中的NSDictionary中存储本机数字类型,所以我不断在NSNumber和数字类型之间来回转换:

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for (MyObject *obj in objs) {  
    NSNumber *old = [dictionary objectForKey:obj.category];
    NSNumber *new = [NSNumber numberWithInteger:1 + old.integerValue];
    [dictionary setObject:new forKey:obj.category];
}
Run Code Online (Sandbox Code Playgroud)

有没有更有效的方法来做到这一点?

algorithm dictionary objective-c

2
推荐指数
1
解决办法
146
查看次数

需要帮助理解目标c代码

我需要一些帮助来理解以下代码:

  1. @"Reload"中'@'的含义是什么

    button = MakeTestButton(&button_rect,@"Reload",content); [button setTarget:web_view]; [button setAction:@selector(reload :)];

  2. 在哪里可以找到"@selector(reload :)"的定义?

objective-c

0
推荐指数
1
解决办法
182
查看次数

将变量插入NSMutableArray对象

我想在NSMutableArray的对象中添加一个预定义的字符串.我以为你会用%@,但显然下面的代码执行得不好.先感谢您

arrayData = [[NSMutableArray alloc]
               initWithObjects:@"%@ you look tired." name,
                               @"Why do you smell so bad?",
                               @"I have to go potty!",
                               @"%@ put your pants on!" name,
                               @"Mommy!",
                               @"Daddy!",
                               @"NOOOOOO!",
                               @"When are we going to get there?",
                               @"I HATE YOU!",
                               nil]; 
Run Code Online (Sandbox Code Playgroud)

iphone cocoa nsmutablearray

0
推荐指数
1
解决办法
284
查看次数

使用橡胶部署时启用hstore

我正在部署一个使用PostgreSQL和HSTORE的Rails应用程序.

为了部署它,我正在使用橡胶.

一切正常,但HSTORE未正确启用除外.当包含execute("CREATE EXTENSION hstore")运行的迁移时,我收到以下错误:

** [out :: production.---] 
** [out :: production.---] -- execute("CREATE EXTENSION hstore")
** [out :: production.---] 
** [out :: production.---] rake aborted!
** [out :: production.---] An error has occurred, this and all later migrations canceled:
** [out :: production.---] 
** [out :: production.---] PG::Error: ERROR:  permission denied to create extension "hstore"
** [out :: production.---] HINT:  Must be superuser to create this extension.
Run Code Online (Sandbox Code Playgroud)

创建postgres实例的脚本具有以下代码:

create_user_cmd = "CREATE USER #{env.db_user} WITH …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails amazon-ec2 hstore rubber

0
推荐指数
1
解决办法
1320
查看次数