小编Vaq*_*ita的帖子

用swift测量经过的时间

我们如何衡量在Swift中运行函数所用的时间?我试图像这样显示经过的时间:"Elasped time is .05 seconds".看到在Java中,我们可以使用System.nanoTime(),是否有任何等效的方法可用于Swift来实现这一目的?

请看一下示例程序:

func isPrime(var number:Int) ->Bool {
    var i = 0;
    for i=2; i<number; i++ {
        if(number % i == 0 && i != 0) {
            return false;
        }
    }
    return true;
}

var number = 5915587277;

if(isPrime(number)) {
    println("Prime number");
} else {
    println("NOT a prime number");
}
Run Code Online (Sandbox Code Playgroud)

time nsdate elapsedtime swift

111
推荐指数
8
解决办法
7万
查看次数

无法访问dispatch_async中的全局变量:"变量不可分配(缺少_block类型说明符)"

在我的dispach_async代码中,block我无法访问global variables.我收到了这个错误Variable is not Assignable (missing _block type specifier).

NSString *textString;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
   (unsigned long)NULL), ^(void) {
        textString = [self getTextString];
});
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我找出原因吗?

multithreading objective-c grand-central-dispatch ios objective-c-blocks

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

使用HTML/JavaScript/CSS沿圆形路径移动div

我想使用HTML/CSS/JavaScript沿着圆形路径移动一个圆圈.有没有办法实现这个目标?圆圈的代码添加如下:

.circle {
    width: 50px;
    height: 50px;
    display: block;
    -webkit-border-radius: 50px;
     -khtml-border-radius: 50px;
       -moz-border-radius: 50px;
            border-radius: 50px;
    color: #fff;
    background-color: #b9c1de;
}
Run Code Online (Sandbox Code Playgroud)
<div class="circle"></div>
Run Code Online (Sandbox Code Playgroud)

html javascript css css3

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

iOS项目中的SIGPIPE异常与BUMP API集成

SIGPIPE在Xcode项目中遇到错误.自一周前开始显示此错误.如果我评论这个方法调用:[self configureBump];一切正常.我在我的项目中集成了BUMP API.这个API工作到一周之前没有任何问题.我不确定这个错误的原因.有谁可以帮我解决这个错误?我的一些朋友也报告了这个错误.

Xcode版本:4.5 iOS版本:iOS 6.0/iOS 5.0

请参阅下面的堆栈跟踪:

* thread #1: tid = 0x1c03, 0x95a887d2 libsystem_kernel.dylib`mach_msg_trap + 10, stop reason = signal SIGPIPE
    frame #0: 0x95a887d2 libsystem_kernel.dylib`mach_msg_trap + 10
    frame #1: 0x95a87cb0 libsystem_kernel.dylib`mach_msg + 68
    frame #2: 0x029ef13a CoreFoundation`__CFRunLoopServiceMachPort + 186
    frame #3: 0x02952580 CoreFoundation`__CFRunLoopRun + 1312
    frame #4: 0x02951db4 CoreFoundation`CFRunLoopRunSpecific + 212
    frame #5: 0x02951ccb CoreFoundation`CFRunLoopRunInMode + 123
    frame #6: 0x03093879 GraphicsServices`GSEventRunModal + 207
    frame #7: 0x0309393e GraphicsServices`GSEventRun + 114
    frame #8: 0x017a0a9b …
Run Code Online (Sandbox Code Playgroud)

objective-c sigpipe bump ios6

7
推荐指数
1
解决办法
2802
查看次数

在iOS中创建包含行和列的表

我想在iOS中创建一个包含行和列的表.我们还可以选择向表中添加金额.示例表的屏幕截图发布在下面: 在此输入图像描述

细胞需要可编辑.有没有办法使用iOS中的默认UITableView来实现它.或者使用按钮或文本字段等创建它是否有用?

objective-c uibutton uitableview ios5

5
推荐指数
1
解决办法
9200
查看次数

XMPP无法在iOS 4.3项目上运行

在My Xcode项目中,我集成了XMPP框架.它在iOS 5.1模拟器上运行良好.当我尝试在iOS 4.3模拟器上运行该项目时,我收到以下错误:

dyld: lazy symbol binding failed: Symbol not found: _objc_storeStrong
  Referenced from: /Users/admin/Library/Application Support/iPhone Simulator/4.3.2/Applications/67451DE6-EFC1-4313-9A29-C2C641F727C6/AppName.app/AppName
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

dyld: Symbol not found: _objc_storeStrong
  Referenced from: /Users/admin/Library/Application Support/iPhone Simulator/4.3.2/Applications/67451DE6-EFC1-4313-9A29-C2C641F727C6/AppName.app/AppName
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation
Run Code Online (Sandbox Code Playgroud)

以下代码行发生错误:xmppStream = [[XMPPStream alloc] init];

进一步调试后,我发现此处发生错误:

- (id)init
{
    if ((self = [super init])) //**CRASH WHEN EXECUTING THIS STATEMENT
    {
        // Common initialization
        [self commonInit];

        // Initialize socket
        asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:xmppQueue];
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)


我整合XMPP的项目不是ARC.所以我在所有XMPP文件中添加了-fobjc-arc.XMPP库提供的示例项目在iOS 4.3模拟器上运行良好.任何人都可以帮我解决这个错误吗?
Xcode版本:4.3.3
iOS:iOS 4.3模拟器

objective-c ios4 xmppframework ios5 xcode4.3

5
推荐指数
1
解决办法
478
查看次数

UILongPressGestureRecognizer不适用于tableview

我在ViewDidLoad方法的桌面视图中添加了一个UILongPressGestureRecognizer.我添加了这个以检测我的代码中的长按表格视图.但它永远不会奏效.在ViewDidLoad中,我添加了以下代码:

UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] 
                                      initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 2.0; //seconds
lpgr.delegate = self;
[self.resultTableView addGestureRecognizer:lpgr];
[lpgr release];
Run Code Online (Sandbox Code Playgroud)

我还添加了这个方法:

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
    CGPoint p = [gestureRecognizer locationInView:self.resultTableView];

    NSIndexPath *indexPath = [self.resultTableView indexPathForRowAtPoint:p];
    if (indexPath == nil) {

        NSLog(@"long press on table view but not on a row");
    }
    else {


        NSLog(@"long press on table view at row %d", indexPath.row);
    }


}
Run Code Online (Sandbox Code Playgroud)

请帮帮我解决这个问题?

xcode objective-c uitableview ios ios5

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

使用文本消息调用Web服务API

现在我正在创建一个iOS应用程序.我还实现了一些Web服务.我的要求是:"用户应该能够通过发送短信(SMS)来调用Web服务API".经过大量研究后,我发现有一家名为Clickatell的供应商(http://www.clickatell.com/).但我不知道如何配置呢?请帮我配置一下.或者是否有其他API或SMS网关提供此服务?

sms web-services sms-gateway ios5

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

将视图添加到滚动视图

我的Viewcontroller中有一个Scroll视图。我还创建了一个视图,并将其连接到IBOutlet变量。我需要向“滚动”视图添加许多视图。

用于将视图添加到ScrollView的代码:

在.h文件中

UIView *customView_;

@property (nonatomic, retain) IBOutlet UIView *customView;
Run Code Online (Sandbox Code Playgroud)

在.m文件中:

@synthesize customView = customView_;

    for (int i = 0; i < 2; i++) {

        UIView *tempView = customView;
        tempView.frame = CGRectMake(i * 187, 0, 187, 133);
        [scrollView addSubview:tempView];
    }
Run Code Online (Sandbox Code Playgroud)

但是使用上面的代码,我只能看到一个位置:187,0,187,133。如果将代码更改为(int i = 0; i < 3; i++) {,则只能在374,0,187,133中看到视图。谁能帮我解决这个错误?

objective-c uiscrollview ios4 ios

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

使用gets函数读取字符时出错

我正在写一个字符串到一个文件.但只有字符串的第一部分才会插入到文件中.其他人都不见了.例如:如果我写"我喜欢花","我"只写入文件.

    #include <stdio.h>
int main()
{
        char string[50];
        int marks,i,n;
        FILE *fptr; fptr=(fopen("string.txt","w"));
        if(fptr==NULL){
                printf("Error!");
                return 0;
        }
        printf("Enter a string : \n");
        scanf("%s", string);
        //fprintf(fptr,"%s",string);
        fwrite(string, 1, sizeof(string), fptr);

        fclose(fptr);
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

c cc

-1
推荐指数
1
解决办法
163
查看次数