小编Art*_*sev的帖子

NSMergeByPropertyObjectTrumpMergePolicy与NSMergeByPropertyStoreTrumpMergePolicy

在我的多线程应用程序中,主线程和一个或多个后台线程可以同时访问,获取和更改核心数据存储中的信息.对于每个线程,我正在创建一个新的NSManagedObjectContext.但是,每个实例NSManagedObjectContext使用相同的"NSPersistentStoreCoordinator"实例(存储在单例中的其他位置).

我的问题是关于每个实例的合并政策NSManagedObjectContext.如果我为后台线程(NSMergeByPropertyStoreTrumpMergePolicy)和NSMergeByPropertyObjectTrumpMergePolicy主线程的另一个策略()设置一个合并策略,是否有内在的好处?

在我的NSMangagedObjectContext吸气器中,我有以下条件:

    if ( [NSThread isMainThread] ) {

        [_context setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];

    } else {

        [_context setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy];
    }
Run Code Online (Sandbox Code Playgroud)

谢谢.

编辑:有必要吗?对于两种类型的线程,我应该默认为一个策略而不是另一个策略吗?

cocoa-touch core-data objective-c ios

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

使用NSLayoutConstraint在Superview中使用UIPageControl进行编程垂直对齐

到目前为止,我能够避免使用自动布局,因此(可能)愚蠢的问题道歉.

  • 我有一个以编程方式构建的ViewController(例如,没有IB).
  • 我有一个UIPageControl对象,它位于viewController视图的视图层次结构中(例如addSubview:)
  • 相反,我需要将UIPageControl对象与UIViewController主视图的下边缘对齐.
  • 我希望UIPageControl水平居中,但距离底部边缘20-40像素.

这里有一些示例代码,它创建UIPageControl并显示它,但根本不在正确的位置.

self.pageControl = [[UIPageControl alloc] init];
self.pageControl.numberOfPages = ...;
self.pageControl.otherAttributes = ...;
[self.view addSubview:[self pageControl]];

UIPageControl *pageControl = [self pageControl];
UIView *view = [self view];
NSDictionary *constaintDictionary = NSDictionaryOfVariableBindings(view, pageControl);


[self.view addConstraint:[NSLayoutConstraint constraintWithItem:pageControl
                                                     attribute:NSLayoutAttributeCenterX
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:self.view
                                                     attribute:NSLayoutAttributeCenterX
                                                    multiplier:1
                                                      constant:0]];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[pageControl]-20-[view]"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:constaintDictionary]];
Run Code Online (Sandbox Code Playgroud)

就像我说的,我对自动布局真的很陌生,所以我不确定我是否正确地实现了这些方法.

感谢您提前给予的帮助.

objective-c ios autolayout nslayoutconstraint ios7

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

NSDate,NTP和运营商时间

我刚刚在文档中读到:

Cocoa根据网络时间协议(NTP)标准实现时间,该标准基于协调世界时.

我是正确的,因为OSX正在与互联网同步,对吗?

那么iOS设备呢?相同的NSObjects(NSDate,NSCalendar等)是否也与互联网同步,或者他们是否从iPhone的运营商那里获得时间(例如,AT&T,Verizon等......)?在获取和同步时间方面,Cocoa-Touch的工作方式与Cocoa的工作方式相同吗?

如果它没有,而是从运营商那里获得时间,那么从互联网上获取iOS应用程序的时间是什么?我不需要示例代码 - 我只需要指向正确的方向.

谢谢!

iphone macos cocoa cocoa-touch objective-c

5
推荐指数
0
解决办法
4194
查看次数

在Facebook Photo Upload上标记朋友

我希望能够使用图形api标记现有的朋友:

这是我目前的代码.照片正在上传,但照片未标记user_id中指定的用户:

        UIImage *testImage = [UIImage imageNamed:@"sendingTo"];
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:kFacebookFBConnectAppID, @"app_id",
                                       testImage, @"source",
                                       @"1381470076", @"message_tags",
                                       @"TEST!", @"message", nil];


        [self.socialIntegration.facebook requestWithGraphPath:[NSString stringWithFormat:@"/me/photos?access_token=%@", self.socialIntegration.facebook.accessToken]
                                                    andParams:params 
                                                andHttpMethod:@"POST" andDelegate:self];
Run Code Online (Sandbox Code Playgroud)

message_tags属性不使用正确的属性?

谢谢!

编辑 从我在这里看到的(https://developers.facebook.com/docs/reference/api/photo/#tags),看起来我需要总共进行三次调用:

  1. 使用我已有的代码发布照片
  2. 让Facebook给我这张照片的ID(我可以从FBRequestDelegate获得)
  3. 发布后标记人物.

cocoa-touch facebook objective-c facebook-graph-api ios

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

使用ARC绘制渐变时,CFArrayRef和NSArray出现问题

我有一个ARC项目,我正在尝试绘制垂直线性渐变.下面的代码适用于模拟器,但EXC_BAD_ACCESS在设备上进行测试时会抛出内存/ 错误.该应用程序使用以下两行代码崩溃:

NSArray *colorArray = [NSArray arrayWithObjects:(__bridge id)topColor, (__bridge id)bottomColor, nil];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colorArray, colorLocations); 
Run Code Online (Sandbox Code Playgroud)

这两行代码取自以下代码(供参考):

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    [self createGradientForContext:context andView:self.captionView];
    [self createGradientForContext:context andView:self.linksView];
    [self createGradientForContext:context andView:self.commentView]; 

}

- (void)createGradientForContext:(CGContextRef)context andView:(UIView *)view
{

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGFloat colorLocations[] = { 0.0f, 1.0f };

    CGColorRef topColor = [[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1.0f] CGColor];
    CGColorRef bottomColor = [[UIColor colorWithRed:48.0f/255.0f green:48.0f/255.0f blue:48.0f/255.0f alpha:1.0f] CGColor];
    NSArray *colorArray = [NSArray arrayWithObjects:(__bridge id)topColor, (__bridge …
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c core-foundation ios automatic-ref-counting

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

可以在App中为iOS App评分吗?

是否有可能让用户在他们使用的应用程序中评估您的应用程序(例如,无需进入AppStore应用程序)在iOS设备上?

谢谢!

编辑:我知道Appirater,但当用户希望他们同意为您的应用评分时,会将用户带到当前应用之外.

iphone app-store ipad ios

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

使用核心动画/ CALayers动画时钟

我有一个4层的UIViewControler.

  1. 手表/时钟的面板
  2. 二手
  3. 分针
  4. 时针

我已经让每只手在正确的时间开始移动(通过根据应用程序加载的时间在圆上定义角度).

如何使用CABasicAnimation存取方法正确定义运动的运动和持续时间(应该是无限的)?

例如,我将我的secondHandMotion(它是一个实例化的CABasicAnimation对象)设置为与当前时间对应的时钟帧上的某个角度:

CABasicAnimation *secondHandMotion = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
secondHandMotion.fromValue = [NSNumber numberWithFloat:sAlpha];
secondHandMotion.toValue = [NSNumber numberWithFloat:(2*M_PI)];
[secondHand addAnimation:secondHandMotion forKey:@"transform"];
Run Code Online (Sandbox Code Playgroud)

sAlpha角度在哪里是时间的函数.的secondHandMotion.toValue说法是错误的,我知道.我怎么告诉它继续移动,并以正确的间隔,1秒钟滴答?

谢谢!

core-animation objective-c nsdate calayer ios

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

Ben Gottlieb的Twitter + OAuth iOS SDK - 用户名参数返回nil

似乎在周末,以下的Delegate方法

- (void)OAuthTwitterController:(SA_OAuthTwitterController *)controller authenticatedWithUsername:(NSString *)username

开始为username参数返回nil.

我想知道是否有其他人使用Ben Gottlieb的SDK可以确认这个问题.

谢谢

twitter cocoa-touch mgtwitterengine ios twitter-oauth

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

关于NSDateFormatter和NSCalendar的问题(涉及时区)

我有以下代码:

    self.formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss a z"];
    timeStampForCity = [formatter stringFromDate:[NSDate date]];
    NSLog(@"%@", timeStampForCity);
    updateDate = [formatter dateFromString:timeStampForCity];
    NSLog(@"%@", updateDate);
Run Code Online (Sandbox Code Playgroud)

NSLog(@"%@", timeStampForCity); 输出:

2011-08-01 10:05:50 PM EDT
Run Code Online (Sandbox Code Playgroud)

但是NSLog(@"%@", updateDate);产出:

2011-08-02 02:05:50 +0000
Run Code Online (Sandbox Code Playgroud)

我需要updateDate在当前时区中显示时间(例如,如第一个NSLog()输出中所示).我该怎么做呢?

编辑1

我也有这个代码:

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit| NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSTimeZoneCalendarUnit;
    NSDateComponents *dateComponents = [gregorian components:unitFlags fromDate:[NSDate date]];
    [dateComponents setTimeZone:[NSTimeZone timeZoneWithName:cityNameFormatted]];
    updateDate = [gregorian dateFromComponents:dateComponents]; …
Run Code Online (Sandbox Code Playgroud)

objective-c nsdate nsdateformatter nstimezone ios

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