小编Sha*_*yaz的帖子

如何在boundingRectWithSize中指定NSLineBreakMode?

 [text boundingRectWithSize:BOLIVIASize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT} context:nil];
Run Code Online (Sandbox Code Playgroud)

这是新的替代品

- (CGSize) sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode) lineBreakMode
Run Code Online (Sandbox Code Playgroud)

但是,如何在boundingRectWithSize上指定lineBreakMode参数?

objective-c ios xcode4.5

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

如何在NSUserDefault中设置实体

我们可以将核心日期实体存储到NSUser NSUserDefault中.我正在尝试保存实体.但它在我想要使用的点返回null.但是如果我尝试保存实体属性.it返回阀门.

下面是我的代码示例,如果我使用以下来保存实体

    MyEntity *newEntity = [self.fetchController objectAtIndexPath:indexPath];
    [[NSUserDefaults standardUserDefaults]setObject:newEntity forKey:@"Act"];
Run Code Online (Sandbox Code Playgroud)

并使用以下内容获取实体.结果为null.

     MyEntity *entityAtOtherClass =[[NSUserDefaults standardUserDefaults] valueForKey:@"Act"];
Run Code Online (Sandbox Code Playgroud)

好像我试图存储实体属性说一些字符串,然后我能够获得此实体对象的值.

[[NSUserDefaults standardUserDefaults]setValue:newEntity.name forKey:@"Activity"];
Run Code Online (Sandbox Code Playgroud)

core-data objective-c nsuserdefaults ios

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

如何创建多个本地通知

我正在尝试在我的应用程序中创建多个本地通知,但出于某种原因,只有第一个通知弹出窗口,其余的只是不起作用,这是我的代码.

我有一个名为criaAlertas的类,它负责创建通知,在该类中我有以下方法:

-(void)setarNotificacao:(NSInteger)quando nome:(UILocalNotification *)notification 
{
    UIApplication *myapp = [UIApplication sharedApplication];

    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:quando];
    notification.alertBody = @"Nice";
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.soundName = UILocalNotificationDefaultSoundName;

    NSMutableArray *arrayOfNOtifications = [[NSMutableArray alloc]init];

    [arrayOfNOtifications addObject:notification];
    myapp.scheduledLocalNotifications = arrayOfNOtifications;
}
Run Code Online (Sandbox Code Playgroud)

所以我实例化了该类的一个对象,并尝试这样做:

    criaAlertas *novoAlerta = [[criaAlertas alloc]init];
    UILocalNotification *notaUm = [[UILocalNotification alloc]init];
    UILocalNotification *notaDois = [[UILocalNotification alloc]init];
    [novoAlerta setarNotificacao:15 nome:notaUm];
    [novoAlerta setarNotificacao:30 nome:notaDois];
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

objective-c foundation ios

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

NSMutableAttributedString不起作用:粗体NSString的一部分

试图加粗NSString的起始部分.使用下面提到的代码.

-(void)setText {

    NSString *strEmail = @"Email: HR_Contact@sre.com";
    NSMutableAttributedString *attributedEmail = [[NSMutableAttributedString alloc]initWithString:strEmail];
    NSString *boldFontName = [[UIFont fontWithName:_fontMyriadBold size:20] fontName];
    NSRange boldedRange = NSMakeRange(0, 5);
    [attributedEmail beginEditing];
    [attributedEmail addAttribute:NSFontAttributeName
                   value:boldFontName
                   range:boldedRange];

    [attributedEmail endEditing];

    lblEmailAddress.attributedText = attributedEmail;
}
Run Code Online (Sandbox Code Playgroud)

它没有任何改变.为什么这样,问题是什么,没有得到任何警告或错误.请指导.提前致谢.

iphone nsstring ios

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

我无法初始化NSInputStream

请帮助我,我疯了.我需要创建一个,NSInputStream所以我可以通过wifi从相机读取实时预览.liveViewStream是一个NSInputStream-Instance-Variable,在我的实现中声明如下:

@implementation MKSonyCamHandler{
    NSInputStream *liveViewStream;
}
Run Code Online (Sandbox Code Playgroud)

liveViewURL是一个有效的URL,当我连接到相机的网络时,我可以在我的浏览器中打开(虽然我不认为这有任何区别).我已经检查过它存在,不是零并且保持我期望的值.但是当我这样做时:

liveViewStream = [[NSInputStream alloc] initWithURL:liveViewURL];
DLog(@"%@", liveViewStream);
Run Code Online (Sandbox Code Playgroud)

alloc-init命令之后的DLog每次都会记录"(null)",如果我知道原因,就会被诅咒.有没有人遇到过这个?我在这里错过了一些明显的东西吗?我第一次与之合作NSStreams,是否有一个常见的陷阱可能是原因?文档清楚地说明了-initWithURL:

Creates and returns an initialized NSInputStream object that reads data from
the file at a given URL.
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我开始觉得这里真的很蠢.

编辑:我正在使用ARC.

iphone cocoa-touch nsinputstream nsstream ios

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

iPhone应用程序杀死进程

我基本上希望创建以下应用程序中给出的内存(RAM)优化功能.(对于iPhone sdk)

https://itunes.apple.com/us/app/memory-100-pro/id644853504?mt=8 https://itunes.apple.com/th/app/memory-pro/id483447668?mt=8

这个功能基本上杀死了第三方app后台进程来实现同样的功能.

任何人都可以指导我如何才能找到特定的过程不是系统过程并杀死过程.

我使用以下代码获取进程ID列表.

struct kinfo_proc *procs = NULL, *newprocs;
char          thiscmd[MAXCOMLEN + 1];
pid_t           thispid;
int           mib[4];
size_t                miblen;
int           i, st, nprocs;
size_t                size;


size = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_ALL;
mib[3] = 0;
miblen = 3;

st = sysctl(mib, miblen, NULL, &size, NULL, 0);
do {
    size += size / 10;
    newprocs = realloc(procs, size);
    if (newprocs == 0) {
        if (procs)
            free(procs);
        errx(1, "could not reallocate memory");
    } …
Run Code Online (Sandbox Code Playgroud)

iphone process objective-c ios

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

退出函数后,NSMutable Array属性变为null

我正在尝试从JSON请求获取CLLocation数组的值,并将它们分配给一个NSMutable数组的属性.这里是相关的控制器代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //using a background thread to receive the json call so that the UI doesn't stall
    dispatch_async(directionQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL:openMapURL];
        [self performSelectorOnMainThread:@selector(fetchedData:)
                               withObject:data waitUntilDone:YES];
    });

    NSLog(@"%@", self.coordinates);
}

- (void)fetchedData:(NSData *)responseData 
{
    //parse out the json data
    NSError* error;
    NSDictionary* json = [NSJSONSerialization
                          JSONObjectWithData:responseData //turn the data from the json request into a gigantic dictionary
                                     options:0
                                       error:&error];

    NSDictionary* route = [json objectForKey:@"route"]; //created a dictionary out of the contents of route
    NSDictionary* …
Run Code Online (Sandbox Code Playgroud)

json objective-c ios

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

预期标识符或'('

我似乎无法压制这个错误!

我正在开发一个小项目,试图为我的应用添加背景音频.在这个错误出现之前我做得很好.

.m文件第52行出错:

//
//  UDMenuScene.m
//  iLabyrinth
//
//  Created by Rolandas Razma on 5/12/10.
//  Copyright 2010 UD7. All rights reserved.
//

#import "UDMenuScene.h"
#import "UDPickMapScene.h"
#import "SimpleAudioEngine.h"
#import "UDHelpScene.h"
#import "iLabyrinth.h"
#import "CCDirector.h"

@implementation UDMenuScene
#pragma mark -
#pragma mark NSObject

- (id)init 
{
    if( (self = [super init]) )
    {
         [self addChild:[UDMenuLayer node]];
    }
    return self;
}

@end

@implementation UDMenuLayer
#pragma mark -
#pragma mark NSObject

- (id)init {

    if( (self = [super init]) )
    { …
Run Code Online (Sandbox Code Playgroud)

objective-c identifier cocos2d-iphone ios

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

一局中有多个skshapenode?

嗨,我为我的视觉a *表示绘制了skshapenodes连接图中的节点。

for(int x=0; x<64; x++)
        {
            for(int y=0; y<48; y++)
            {
                PathFindingNode *node = [[gridToDraw objectAtIndex:x] objectAtIndex:y];
                for(int i=0; i< node.connections.count; i++)
                {
                    PathFindingNode *neighbor = [node.connections objectAtIndex:i];

                    SKShapeNode *line = [SKShapeNode node];
                    CGMutablePathRef pathToDraw = CGPathCreateMutable();
                    CGPathMoveToPoint(pathToDraw, NULL, node.position.x, node.position.y);
                    CGPathAddLineToPoint(pathToDraw, NULL, neighbor.position.x, neighbor.position.y);
                    line.path = pathToDraw;
                    line.lineWidth = 0.1f;
                    [line setStrokeColor:[UIColor blueColor]];
                    line.alpha = 0.1f;
                    [self addChild:line];
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

我的图中有很多节点,它绘制了将近22,000个形状。有没有一种方法可以在一次绘制调用中绘制这些形状,因为它们都是相同的,唯一的区别是它们的开始和结束位置。

如果我改为使用可以一次加载的纹理,那么如何改变它的旋转度以像上面那样连接我的所有节点。

问候,

更新:

SKShapeNode *line = [SKShapeNode node];
        CGMutablePathRef pathToDraw = CGPathCreateMutable();

        for(int x=0; x<64; x++) …
Run Code Online (Sandbox Code Playgroud)

ios ios7 sprite-kit skshapenode

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

这是在iOS中调用方法的正确方法

我曾经使用iOS,但我没有得到这个所有方法有什么区别,

我应该使用哪种语法来调用MehodName

 (1) [self MehodName];

 (2) [self performSelector:@selector(MehodName) withObject:nil];

 (3) [self performSelectorInBackground:@selector(MehodName) withObject:nil];

 (4) [self performSelectorOnMainThread:@selector(MehodName) withObject:nil waitUntilDone:YES];

 (5) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
                                         (unsigned long)NULL), ^(void) {
    [self MehodName];
});

  (6) dispatch_sync(dispatch_get_main_queue(), ^{
     [self MehodName];       
});
Run Code Online (Sandbox Code Playgroud)

请提前帮助和谢谢.

objective-c method-call

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