标签: repeat

iPhone dev - performSelector:withObject:afterDelay或NSTimer?

要重复一个方法调用(或消息发送,我猜适当的术语是)每x秒,是否更好地使用NSTimer(NSTimer的scheduledTimerWithTimeInterval:target:selector:userInfo:repeats :)或让该方法以递归方式调用自身结束(使用performSelector:withObject:afterDelay)?后者不使用对象,但可能不太清晰/可读?另外,为了让您了解我正在做什么,它只是一个带有标签的视图,倒计时到午夜12点,当它变为0时,它会闪烁时间(00:00:00)并永远发出哔哔声.

谢谢.

编辑:同样,重复播放SystemSoundID(永远)的最佳方法是什么?编辑:我最终使用它来永远播放SystemSoundID:

// Utilities.h
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioServices.h>


static void soundCompleted(SystemSoundID soundID, void *myself);

@interface Utilities : NSObject {

}

+ (SystemSoundID)createSystemSoundIDFromFile:(NSString *)fileName ofType:(NSString *)type;
+ (void)playAndRepeatSystemSoundID:(SystemSoundID)soundID;
+ (void)stopPlayingAndDisposeSystemSoundID;

@end


// Utilities.m
#import "Utilities.h"


static BOOL play;

static void soundCompleted(SystemSoundID soundID, void *interval) {
    if(play) {
        [NSThread sleepForTimeInterval:(NSTimeInterval)interval];
        AudioServicesPlaySystemSound(soundID);
    } else {
        AudioServicesRemoveSystemSoundCompletion(soundID);
        AudioServicesDisposeSystemSoundID(soundID);
    }

}

@implementation Utilities

+ (SystemSoundID)createSystemSoundIDFromFile:(NSString *)fileName ofType:(NSString *)type {
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];
    SystemSoundID soundID;

    NSURL *filePath = …
Run Code Online (Sandbox Code Playgroud)

iphone tail-recursion repeat nstimer

10
推荐指数
1
解决办法
7474
查看次数

如何根据行本身的数量字段返回多个相同的行?

我正在使用oracle从购物应用中输出订单项.每个项目的数量字段可能大于1,如果是,我想将该行返回N次.

这就是我正在谈论的一张桌子

product_id, quanity
1, 3,
2, 5
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个可以返回的查询

1,3
1,3
1,3
2,5
2,5
2,5
2,5
2,5
Run Code Online (Sandbox Code Playgroud)

这可能吗?我看到了SQL Server 2005的这个答案,我正在寻找oracle中几乎所有的东西.遗憾的是,建立专用号码表不是一种选择.

oracle select repeat rownum

10
推荐指数
1
解决办法
1万
查看次数

在字符串上找到重复的单词并计算重复次数

我需要在字符串上找到重复的单词,然后计算它们被重复的次数.所以基本上,如果输入字符串是这样的:

String s = "House, House, House, Dog, Dog, Dog, Dog";
Run Code Online (Sandbox Code Playgroud)

我需要创建一个没有重复的新字符串列表,并在其他地方保存每个单词的重复次数,如下所示:

新字符串:"House,Dog"

新的Int数组:[3,4]

有没有办法用Java轻松完成这项工作?我已经设法使用s.split()分隔字符串但是我如何计算重复并在新字符串上消除它们?谢谢!

java string repeat

10
推荐指数
1
解决办法
18万
查看次数

检查字符串Javascript中的重复字符

我想知道是否有办法检查字符串中的重复字符而不使用双循环.这可以通过递归来完成吗?

使用双循环的代码示例(如果字符串中有重复的字符,则返回true或false):

var charRepeats = function(str) {
    for(var i = 0; i <= str.length; i++) {
        for(var j = i+1; j <= str.length; j++) {
            if(str[j] == str[i]) {
                return false;
            }
        }
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

提前谢谢了!

javascript recursion repeat

10
推荐指数
3
解决办法
2万
查看次数

如何在 SymPy 中定义大量符号

我试图在“sympy”中定义很多变量以进行符号处理。

import sympy as sp

b_0 = sp.symbols('b_0')
b_1 = sp.symbols('b_1')
...
b_X = sp.symbols('b_X')
Run Code Online (Sandbox Code Playgroud)

依此类推,X从 1 到 1000。

有简单的方法吗?

symbols repeat sympy

10
推荐指数
1
解决办法
5989
查看次数

AlarmManager - 如何在每小时的顶部重复闹钟?

我想要每小时开一次活动(5:00,6:00,7:00等).我尝试使用线程的持久后台服务,但它不是正确的解决方案,因为:

  • 电池消耗
  • 服务终止,由于android内存管理

所以我正在尝试使用AlarmManager.如果我将警报设置为在X秒内触发(使用"set"方法),它就可以工作.但是如何在每小时的顶部重复一次事件(使用"setRepeating"方法),直到警报被取消?

谢谢!

android repeat alarmmanager

9
推荐指数
1
解决办法
1万
查看次数

为什么ListView每隔6个项重复一次?

我有一个ListView,由具有特定布局的自定义适配器填充.适配器映射到具有特定元素的HashMap,其中包含每个ListView元素的数据.

hashMap中的数据是正确的,但ListView重复绘制每6个相同的第6个元素,直到它到达Map的末尾?

我的显示器允许显示5个项目,如果你滚动一下它是6个项目.

这是适配器的代码,ListActivity的相关代码和ListView的布局文件.

请帮忙,我不知道为什么会这样.

package de.View;

import java.util.ArrayList;
import java.util.Map;

import de.carSync.R;
import de.Common.Date_Conversion;
import de.Common.GUI_Output;
import de.Model.DriversLog.Fahrt;
import de.Model.DriversLog.Geladene_Fahrten;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Fahrten_List_Adapter extends BaseAdapter{

    private static  String TAG = "Fahrten_List_Adapter";

    private Map<Integer,Fahrt> fahrten_Liste;

    private final LayoutInflater mLayoutInflater;

    int zeilen_Layout;

    public Fahrten_List_Adapter(Context ctx, Map<Integer,Fahrt> f_l, int zeilen_Layout){
        this.zeilen_Layout = zeilen_Layout;
        fahrten_Liste = f_l;
        mLayoutInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return fahrten_Liste.size(); …
Run Code Online (Sandbox Code Playgroud)

android listview repeat

9
推荐指数
1
解决办法
7580
查看次数

根据列值重复N次

我有下表.

Table A:
ID         ProductFK         Quantity       Price
------------------------------------------------
10         1                  2           100
11         2                  3           150
12         1                  1           120
----------------------------------------------
Run Code Online (Sandbox Code Playgroud)

我需要根据订单列值选择重复行N次.

所以我需要以下选择结果:

ID        ProductFK         Quantity        Price
------------------------------------------------
10        1                   1          100
10        1                   1          100
11        2                   1          150
11        2                   1          150
11        2                   1          150
12        1                   1          120
Run Code Online (Sandbox Code Playgroud)

sql t-sql repeat sql-server-2008

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

重复在向量中的元素与for循环

我想在R中从3:50制作一个矢量,看起来像

3 4 4 5 6 6 7 8 8 .. 50 50

我想在for循环中使用for循环,但它不是我想要的wat.

f <- c()
for (i in 3:50) {
  for(j in 1:2) {
    f = c(f, i)
  }
}
Run Code Online (Sandbox Code Playgroud)

这有什么问题?

loops for-loop r vector repeat

9
推荐指数
4
解决办法
1327
查看次数

Android - 如何避免多个Manifest文件中的重复?

我的项目有3个Manifest文件:

flavour/AndroidManifest.xml
flavourDebug/AndroidManifest.xml
flavourRelease/AndroidManifest.xml
Run Code Online (Sandbox Code Playgroud)

这是flavor/AndroidManifest.xml:

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.READ_CONTACTS" />
</manifest>
Run Code Online (Sandbox Code Playgroud)

这是flavourDebug/AndroidManifest.xml:

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application android:name="com.domain.android.MyApplication"
        android:allowBackup="false"
        android:label="@string/app_name"
        android:logo="@drawable/ic_logo"
        android:theme="@style/Theme.CustomActionBarStyle"
        android:networkSecurityConfig="@xml/network_security_config"
        tools:replace="theme">

        // Activity definitions in here

     </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

这是flavourRelease/AndroidManifest.xml:

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application android:name="com.domain.android.MyApplication"
        android:allowBackup="false"
        android:label="@string/app_name"
        android:logo="@drawable/ic_logo"
        android:theme="@style/Theme.CustomActionBarStyle"
        tools:replace="theme">

        // Activity definitions in here (these are the EXACT SAME as the ones in flavourDebug/AndroidManifest.xml)

     </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

如您所见,Debug和Release Manifests之间的唯一区别是Release 1缺失 android:networkSecurityConfig

此外,该// Activity definitions in here部分完全相同.我想要的是避免重复活动.每次我们必须在Activity定义中更改某些内容(或添加一个新的Activity)时,我们必须在2个Manifest文件(Debug和Release)中执行此操作.

我想把所有东西放在AndroidManifest.xml主文件中.问题是我无法android:networkSecurityConfig="@xml/network_security_config" 添加到调试版本.

在Android布局中,该问题通过<include>标记解决.不幸的是,Manifest中没有.

我怎样才能解决这个重复问题?

android manifest include repeat android-manifest

9
推荐指数
1
解决办法
441
查看次数