小编Noa*_*ick的帖子

如何使用iOS 7和8支持NSCalendar?

iOS 8为旧方法引入了一些新值.例如,创建日历曾经是这样的:

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
Run Code Online (Sandbox Code Playgroud)

现在,日历标识符已更改,我应该像这样创建对象:

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
Run Code Online (Sandbox Code Playgroud)

事情是,编译器只在第一种情况下警告我不推荐使用NSGregorianCalendar.但是,编译器并没有警告我NSCalendarIdentifierGregorian与iOS 7的兼容性.这
是否意味着NSCalendarIdentifierGregorian在iOS 7下工作?
如果没有,根据操作系统创建带日历标识符的日历的最佳方法是什么?每次检查操作系统版本似乎很乏味.

谢谢.

objective-c ios ios8

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

TCP拥塞控制 - 图中的快速恢复

我一直在阅读"计算机网络:自上而下的方法"一书,并遇到了一个我似乎不理解的问题.

正如我所读到的,TCP拥塞控制有三种状态:慢启动,拥塞避免和快速恢复.我很了解慢启动和拥塞避免,但快速恢复非常模糊.该书声称TCP的行为方式如下:(cwnd =拥塞窗口) 在此输入图像描述
我们来看下面的图表: 传输轮 - 拥塞窗口大小图

我们可以看到,在第16轮,发送方发送了42个段,并且因为拥塞窗口大小减半(+3),我们可以推断出有3个重复ACK.这个问题的答案声称 16到22之间的轮次处于拥塞避免状态.但为什么不快速恢复?我的意思是,在三次重复的ACK之后,TCP进入快速恢复并且每隔一次重复的ACK都应该增加拥塞窗口.为什么图表没有表示?我能想到的唯一合理的解释是,在这个图中,只有三个重复的ACK,并且之后收到的ACK不是重复的.

即使是这种情况,如果有超过3个重复的ACK,图表将如何显示?**

上图中是否有快速恢复的表示?为什么不/是的?

**我一直在努力回答这个问题很长一段时间.我会很高兴回复,谢谢!

更新这里是图像.我认为轮次定义为窗口中的所有段都被确认.在照片中,圆圈显示为圆圈. 在此输入图像描述 为什么cwnd在快速恢复状态下呈指数级增长?(在图像中我偶然写了而不是指数地写)

networking tcp network-protocols congestion-control

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

更新核心数据存储位置以支持应用程序组


我已经在App Store中有一个应用程序,它使用核心数据来保存数据.
现在,当iOS 8即将问世时,我想为它添加一个小部件,因此我必须使用App Groups在二进制文件之间共享数据.
但有一个问题 - 我需要更改商店位置以支持应用程序组到所有现有用户.
我编写了以下代码,试图将商店移动到新路径:

// Returns the persistent store coordinator for the application.
// If the coordinator doesn't already exist, it is created and the application's store added to it.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    NSURL *oldStoreURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    oldStoreURL = [oldStoreURL URLByAppendingPathComponent:@"Schooler.sqlite"];


    NSURL *storeURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.schooler.mycontainer"];
    storeURL = [storeURL URLByAppendingPathComponent:@"Schooler.sqlite"];


    if([[NSFileManager defaultManager] fileExistsAtPath:oldStoreURL.path] == YES && [[NSFileManager defaultManager] fileExistsAtPath:storeURL.path] == NO) …
Run Code Online (Sandbox Code Playgroud)

core-data ios8

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

Pty 没有关闭,尽管调用了 close() 系统调用

我正在实现 ssh 服务器的功能,因此根据 shell 请求,我打开一个 pty-tty 对。
一个片段:

import (
    "github.com/creack/pty"
    ...
)

func attachPty(channel ssh.Channel, shell *exec.Cmd) {
    mypty, err := pty.Start(shell)
    go func() {
        io.Copy(channel, mypty) // (1) ; could also be substituted with read() syscall, same problem
    }
    go func() {
        io.Copy(mypty, channel) // (2) - this returns on channel exit with eof, so let's close mypty
        if err := syscall.Close(int(mypty.Fd())); err != nil {
            fmt.Printf("error closing fd") // no error is printed out, /proc/fd shows it's …
Run Code Online (Sandbox Code Playgroud)

linux terminal go linux-kernel pty

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

核心数据应该有倒数

可能重复:
每个核心数据关系都必须具有反转吗?

我有以下关系的实体: 在此输入图像描述

一个CombinedSH必须有一个Subject和一个StudyHour.
一个Subject不能有CombinedSH.
一个StudyHour不能有CombinedSH.

在我的应用程序中,a Subject/ a StudyHour将有一个没有意义CombinedSH.问题是Xcode给了我以下警告:

警告:配置错误的属性:CombinedSH.studyHour应该有反向.

警告:配置错误的属性:CombinedSH.subject应该有反向.

所以Xcode说应该有反向 - 但在我的应用程序中它没有意义.我该怎么办?

core-data objective-c ios

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

尝试仅使用NSDate时间

我正在努力寻找一种方法来使用NSDate仅用于时间目的.我试图做以下代码:

- (void)awakeFromInsert
{
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    comps.minute = 45;
    comps.second = 0;

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    self.periodDuration = [calendar dateFromComponents:comps];
    NSLog(@"periodDuration: %@",self.periodDuration);

    comps = [[NSDateComponents alloc] init];
    comps.hour = 8;
    comps.minute = 0;
    self.firstPeriodStartTime = [calendar dateFromComponents:comps];
    NSLog(@"firstPeriodTime: %@",self.periodDuration);
}
Run Code Online (Sandbox Code Playgroud)

但我得到的结果是:

periodDuration: 0001-12-31 22:24:04 +0000
firstPeriodTime: 0001-12-31 22:24:04 +0000
Run Code Online (Sandbox Code Playgroud)

结果我期待:

periodDuration: 45:00
firstPeriodTime: 08:00
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我怎样才能解决这个问题?谢谢.

xcode objective-c nsdate nsdatecomponents ios

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

关于UIScrollView的一些问题

我很难理解你可能会发现的一些简单的问题UIScrollView.

  1. 为什么我们增加contentSize而不是增加UIScrollView?实际上,我不明白界限和contentSize做法.

  2. 当我设置pagingEnabled为YES时,scrollView如何知道停止滚动的位置?

  3. 我想在我的页面之间添加间隙UIScrollView.(pagingEnabled = YES)我在互联网上搜索,我发现以下代码,rob mayoff写道:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];

    #define kGutterWidth 20

    UIScrollView *scrollView = self.scrollView;
    CGRect scrollViewFrame = scrollView.frame;
    scrollViewFrame.size.width += kGutterWidth;
    scrollView.frame = scrollViewFrame;

    CGSize scrollViewSize = scrollView.bounds.size;

    for (int i = 0; i < colors.count; i++) {
        CGRect frame = CGRectMake(scrollViewSize.width * i, 0,
            scrollViewSize.width - kGutterWidth, scrollViewSize.height);
        UIView …
Run Code Online (Sandbox Code Playgroud)

objective-c uiscrollview ios

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

如何将UILabel的textColor与其背景相匹配?


我有一个背景图片,上面有一些UILabel.
用户可以将背景图像更改为任何颜色,而我必须确定哪种颜色可以更好地用于UILabels,白色还是黑色?

最好的例子是iOS 7 Home Screen.
当背景暗时,文本变为白色,反之亦然.
但是,当背景介于黑暗和光线之间时,例如:半图像100%白色,另一半100%黑色 - 文本变为白色,并添加阴影效果,因此它将是可读的.

我一直面临的问题是如何指出这是什么类型的图像?
天黑了吗?这很轻吗?它是在暗光之间吗?
我怎样才能将这一点变为人类对代码的清晰度?

我明显想自己编写代码,但我不知道.
我开始学习对比度和亮度,但我无法将各个部分粘在一起.
我应该从哪里开始?非常感谢!

objective-c uiimage ios

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

TableView reloadData不会调用cellForRowAtIndexPath

我有两个视图控制器/ 1. SetupRingBoardViewController 2. SetupRingBoard*ADD*ViewController

第一个视图控制器是UITableViewController.当我们第一次启动视图时--ViewController有一个固定的部分,有一个固定的行.在那个ViewController中,有一个调用SetupRingBoardADDViewController的UIBarButton(模态 - 默认,我使用的是storyboard).

第二个视图控制器是UIView控制器.这个viewController包含一个UITableView和一个UINavigationBar.UITableView实际上是一个大的形式,用户可以在其中输入数据.UINavigationBar包含一个'Add'UIBarButton.按下此按钮时,将调用方法"addButton".

'addButton'方法应该刷新SetupRingBoardViewController中的UITableView. 最后,在按下'addButton'按钮后 - 在SetupRingBoardViewController的UITableView中应该有2个部分: 1.固定部分,其中有1行.2.一行中有X行,每行都有一个标题:@"A Row!"; (X =被按下的'addButton'的数量).

最后,这是代码:

SetupRingBoardViewController.h:

//
//  SetupRingBoardViewController.h
// 
//
//  Created by  on 12/24/12.
//  Copyright (c) 2012 Noam. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "SetupRingBoardADDViewController.h"
//#import "StudyHour.h"

@interface SetupRingBoardViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *listOfStudyHours;

@end
Run Code Online (Sandbox Code Playgroud)

SetupRingBoardViewController.m:

//
//  SetupRingBoardViewController.m
//  
//
//  Created by on 12/24/12.
//  Copyright (c) 2012 Noam. All rights reserved.
//

#import "SetupRingBoardViewController.h"
#import "SetupEmptyListViewController.h" …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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