小编Dav*_*ist的帖子

NSMutableArray没有正确地将数据存储到循环中

我尝试将一些存储NSMutableDictionariesNSMutableArray一个for循环中:

NSMutableArray *productsIdAndQuantities = [[NSMutableArray alloc]init];
NSMutableDictionary *element = [[NSMutableDictionary alloc]init];

for (id object in shoppingArray) {
    [element setObject:[object valueForKey:@"proId"] forKey:@"id"];
    [element setObject:[object valueForKey:@"qty"] forKey:@"quantity"];
    NSLog(@"%@",element);//tested, it's different on every iteration
    [productsIdAndQuantities addObject:element];
}
Run Code Online (Sandbox Code Playgroud)

循环结束后,我尝试调试productsIdAndQuantities,刚出来它包含上面循环的项目的确切数量,但有一个值.

这就是我的意思:

在循环内部(NSLog(@"%@",element);):

{
    id = 13293;
    quantity = "-2";
}
{
    id = 12632;
    quantity = "-5";
}
Run Code Online (Sandbox Code Playgroud)

循环之后(NSLog(@"%@",productsIdAndQuantities);相同的值!!!!!):

(
    {
        id = 12632;
        quantity = "-5";
    },
    {
        id = 12632;
        quantity = "-5"; …
Run Code Online (Sandbox Code Playgroud)

nsmutablearray ios

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

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

NSInteger = NSInteger -1?

我想做一件非常简单的事,但我无法弄清楚如何;

NSInteger * a=10;
a=a-1;
NSlog(@"a=%d",a);
Run Code Online (Sandbox Code Playgroud)

出于某种原因,它正在显示a=6.

怎么会这样?

objective-c

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

延迟位置更新问题ios

我一直在尝试在过去两天在应用中实施延迟位置更新.我面临的问题是

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
Run Code Online (Sandbox Code Playgroud)

即使在我调用之后,方法也会被调用

 [self.locMgr allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)200 timeout:(NSTimeInterval)25];
Run Code Online (Sandbox Code Playgroud)

方法.

虽然我不得不说

 - (void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error
Run Code Online (Sandbox Code Playgroud)

在我的allowDeferredLocationUpdatesUntilTraveled方法指定的25秒之后完全调用,错误代码= null.

我从文档中了解到,仅在25秒后才会调用didUpdateLocations.任何帮助将非常感激.

iphone ios

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

如何向NSPredicate添加多个字段

我想使用查询字符串在名字或姓氏上搜索一组用户.下面是谓词,但我得到了一个例外.

NSPredicate *sortingPred = [NSPredicate predicateWithFormat:@"(User.first contains[c] %@) OR (User.last contains[c] %@)", keyword, keyword];
Run Code Online (Sandbox Code Playgroud)

例外:

exception   NSException *   name:@"NSUnknownKeyException" reason:@"[<User 0x12911980> valueForUndefinedKey:]: this class is not key value coding-compliant for the key User."   0x13653620
Run Code Online (Sandbox Code Playgroud)

objective-c nspredicate ios

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

动画CAShapeLayer

我用这段代码画了一个图:

CAShapeLayer *curentGraph = [CAShapeLayer new];
CGMutablePathRef linePath = CGPathCreateMutable();
curentGraph.lineWidth = 3.0f;
curentGraph.fillColor = [[UIColor clearColor] CGColor];
curentGraph.strokeColor = [colorGraph CGColor];
for (NSValue *value in arrOfPoints) {
    CGPoint pt = [value CGPointValue];
    CGPathAddLineToPoint(linePath, NULL, pt.x,pt.y);
};
curentGraph.path = linePath;CGPathRelease(linePath);
[self.layer addSublayer:curentGraph];
Run Code Online (Sandbox Code Playgroud)

它看起来像这样

图表截图

但我有一个问题.我需要为图形显示动画.每个点都应该从位置向上移动y = 0y = pt.y.就像他们在本网站的图表中所做的那样.

如何为我的图形设置动画?

iphone core-animation objective-c cashapelayer ios

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

我怎样才能在ios中获得当地时区?

我需要根据ios设备的位置设置本地时区.

[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; 
Run Code Online (Sandbox Code Playgroud)

要么

[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GTC+5.30"]]; 
Run Code Online (Sandbox Code Playgroud)

适合吗?

timezone ios

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

Swift-animate CAshapeLayer笔触颜色

我正试图找到一种方法来动画我正在创建的笔画的颜色

circleLayer = CAShapeLayer()
circleLayer.path = circlePath.CGPath
circleLayer.lineCap =  kCALineCapRound
circleLayer.fillColor = UIColor.clearColor().CGColor
CABasicAnimation fill = CABasicAnimation.
circleLayer.strokeColor = UIColor(red: 0.4, green: 1.0, blue: 0.2, alpha: 0.5).CGColor
circleLayer.lineWidth = 20.0;
circleLayer.lineJoin = kCALineJoinRound
// Don't draw the circle initially
circleLayer.strokeEnd = 0.0

// Add the circleLayer to the view's layer's sublayers
layer.addSublayer(circleLayer)
Run Code Online (Sandbox Code Playgroud)

我想要实现的是:当它被创建时(我创建它持续1秒),颜色将自动生成

cashapelayer uiviewanimation swift

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

我可以为非 NSString 数据类型匹配 NSPredicate 吗?

在我的模型类(Beacon.h)中,我有这个属性

@property (strong, nonatomic, readonly) NSUUID *uuid;
Run Code Online (Sandbox Code Playgroud)

我有一个包含该 Beacon 类对象的数组,我想使用 NSPredicate 对其进行过滤。如果 uuid 类型是字符串,它会起作用:

@property (strong, nonatomic, readonly) NSString *uuid;

// ..

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"uuid ==[c] %@ ",strUUID];
NSArray *filterArray = [self.arrBeacons filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)

当 uuid 属性是 NSUUID(不是 NSString)时,如何编写 NSPredicate。

objective-c ios

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

我可以使用AVAudioPlayer播放振动声音吗?

我有AVAudioPlayer在聊天期间播放消息提示音,我也想让手机振动.是否可以在AVAudioPlayer中执行此操作或者是否需要使用其他方法?

谢谢

avaudioplayer ios

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