小编Ale*_*one的帖子

Xcode如何在构建iPad应用程序时停止右面板始终打开?

我正在运行 5.0.1 版 (5A2053),每次单击播放按钮在 iPad 上运行我的应用程序时,都会打开右侧面板。

它对我没有任何价值,在关闭它约 200 次后,我很感兴趣是否有一些 Xcode 5.0.1 设置来防止在设备上运行应用程序时显示右侧面板。

抱歉,如果这个问题不是非常面向编程,但随着时间的推移,它肯定会增加一些挫折感。

xcode

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

使用KVO和delayedSelector观察NSUserDefaults时的iOS exc_bad_access

我遇到了一个奇怪的错误,想检查我是否正在使用我的Key值正确观察NSUserDefaults的变化.

我在我的应用程序的两个地方使用了这个代码没有问题,然后我添加了第三个控制器,它观察"goldCount"和"energyCount"的值.现在,当我设置初始值时,应用程序崩溃与exc_bad_access.我在使用父视图后2秒将该控制器添加到视图中performSelectorAfterDelay.

在显示游戏屏幕之前,我设置了以下属性:

//crash on this line 
[[NSUserDefaults standardUserDefaults] setInteger:200 forKey: goldCount]; 

[[NSUserDefaults standardUserDefaults] setInteger:150 forKey: energyCount];
Run Code Online (Sandbox Code Playgroud)

在3个不同的视图控制器中,我在viewDidLoad中有这个代码:

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults addObserver:self
           forKeyPath:@"goldCount"
              options:NSKeyValueObservingOptionNew
              context:NULL];

[defaults addObserver:self
           forKeyPath:@"energyCount"
              options:NSKeyValueObservingOptionNew
              context:NULL];

self.goldLabel.text = [NSString stringWithFormat:@"%i",[[GameDataManager sharedInstance] currentGoldCount]];
self.energyLabel.text = [NSString stringWithFormat:@"%i",[[GameDataManager sharedInstance] currentEnergyCount]];
Run Code Online (Sandbox Code Playgroud)

以下是该类更新其标签的方式:

// KVO handler
-(void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject
                       change:(NSDictionary *)aChange context:(void *)aContext
{

    //aKeyPath gives us the name of a user default that has changed
    if([aKeyPath isEqualToString:@"goldCount"])
    {
        //we are interested in the new …
Run Code Online (Sandbox Code Playgroud)

exc-bad-access objective-c key-value-observing nsuserdefaults ios

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

Objective-C如何从NSArray中提取几个随机项而不会出现重复项?

我有一系列随机属性我想分配给我正在开发的游戏中的设备.

我在下面使用的代码是返回NSArray.我很感兴趣,如果有方法从该数组中获取项索引而不获取重复值.显而易见的解决方案是使用返回的数组创建一个可变数组,执行随机操作,删除返回的项目并循环直到收到项目数.

但是有没有不同的方法从NSArray获取X随机项而不会重复?

//get possible enchantments
NSPredicate *p = [NSPredicate predicateWithFormat:@"type = %i AND grade >= %i", kEnchantmentArmor,armor.grade];

NSArray* possibleEnchantments = [[EquipmentGenerator allEnchantmentDictionary] objectForKey:@"enchantments"];

//get only applicable enchantments
NSArray *validEnchantments = [possibleEnchantments filteredArrayUsingPredicate:p];
NSMutableArray* mutableArray = [NSMutableArray arrayWithArray:validEnchantments];

NSDictionary* enchantment = nil;

if(mutableArray.count>0)
{
    //got enchantments, assign number and intensity based on grade
    for (int i = 0; i<3;i++)
    {
        enchantment = mutableArray[arc4random()%mutableArray.count];
        [mutableArray removeObject:enchantment];

        //create enchantment from dictionary and assign to item.
    }

}
Run Code Online (Sandbox Code Playgroud)

random objective-c nsarray ios

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

iOS9故事板"为变量设置空向量"异常 - 由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序

我遇到了一个问题,我的主要故事板在我乱搞之后被破坏了,我得到了以下神秘的错误消息.该应用程序捕获错误,main()然后SIGABRT出现以下异常:

  Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: '{objective 0x147dc56e0: <1:-25.3333> + <1:1>*0x147dc39b0.posErrorMarker{id: 91} +
 <1:0.125>*0x147dc50e0.negError{id: 90} +
 <1:-0.125>*0x147e2e300.marker{id: 77} +
 <1:0.125>*0x147e2e300.slack{id: 78} +
 <1:0.125>*0x147e2e350.marker{id: 81} +
 <1:-1>*0x147e2e440.marker{id: 87} +
 <1:-0.125>*0x147e436b0.marker{id: 63} +
 <1:0.125>*0x147e437f0.marker{id: 72} +
 <1:-0.125>*0x147e764c0.marker{id: 55} +
 <1:0.125>*0x147e88820.marker{id: 52}}:
 internal error.  Setting empty vector for variable 0x147dc1b90.negError{id: 48}.'
Run Code Online (Sandbox Code Playgroud)

将另一个故事板设置为主界面可以正确启动应用程序.

如何找到导致"为变量设置空向量"故事板异常的元素?

exception objective-c uistoryboard ios9

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

iOS Swift 如何为任何语言环境设置没有年份的 DateFormatter?

我想从两个日期创建一个日期字符串,格式如下:

"Apr 21 - Sep 17, 2018" - US
"21 Apr - 17 Sep, 2018" - Elsewhere
Run Code Online (Sandbox Code Playgroud)

同时尊重本地日期格式(美国为 MMM dd,欧洲为 dd MMM 等)。

如何让 DateFormatter 为我提供默认样式但没有年份?

let startDateFormatter = DateFormatter()
// How to keep medium style but without year?
// this is the US style, 
// I want locale-independent style to match the other date formatter
startDateFormatter.dateFormat = "MMM dd" 

let endDateFormatter = DateFormatter()
endDateFormatter.dateStyle = .medium
endDateFormatter.timeStyle = .none

let startDateText = startDateFormatter.string(from: startDate)
let endDateText   = endDateFormatter.string(from: endDate)
Run Code Online (Sandbox Code Playgroud)

date nsdateformatter ios swift dateformatter

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

iPhone4 iOS5从后台选择器刷新UITableView是否安全?

我在我的一个视图控制器上有一个UITableView,它使用来自我的应用程序的多个部分的日志消息进行异步更新.它工作得很好,但今天我发现了一个奇怪的错误.大约2个小时后,整个桌面视图变为空白.没有单元格,没有行分隔符,只有背景颜色.

此tableview只有2条入口路径.

NSMutableArray* tableViewCellData;

//in the init method:
 tableViewCellData = [[NSMutableArray alloc]initWithCapacity:15];

 -(void)setContextActionWithTitle:(NSString *)title description:(NSString *)description

        ContextConsoleLogItem* temp = [[ContextConsoleLogItem alloc] initWithDate:[NSDate date] title:title message:description contextAction:kNoContextAction];
        [tableViewCellData insertObject:temp atIndex:0];  
        [contextActionTableView reloadData];
    }

//pretty standard data source management
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return kNumberOfSections;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [tableViewCellData count];
}

//here's how the cell displays itself.
    #pragma mark -
    #pragma mark Cell …
Run Code Online (Sandbox Code Playgroud)

multithreading objective-c uitableview iphone-4 ios5

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

iPhone iOS处理内存警告最常用的方法是什么?

我很惊讶iOS 5.1没有像我预期的那样管理内存.当设备运行很多应用程序时,似乎iOS不会在后台杀死内存占用应用程序,但也向我自己的应用程序发送内存警告.

例如,显示UIImagePicker在两个测试设备上崩溃了应用程序.双击主页键并查杀某些后台应用程序可防止应用程序收到内存警告并崩溃.

如果iOS不能为我释放内存,我会徘徊,是否可以显示某种警报视图,通知用户内存不足并且某些后台任务必须被杀死?

我不知道如何处理这类事件 - iOS是否需要时间来清理一些内存(而应用程序会响应内存警告)?

iphone memory-management ios5.1

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

Java字符串如何替换"with"来逃避JSON?

我试图"\"Java 替换,但所有的斜杠都变得非常混乱."\"Java 替换的正确方法是什么?

string.replaceAll("\"","\\"");
Run Code Online (Sandbox Code Playgroud)

java regex replace escaping

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

算法 - 我可以使用内置实用函数进行在线编码面试和挑战吗?

我有很多基于算法的编码面试 (coderpad.io) 和在线挑战,例如 Objective-c 中出现的 hackerrank。我不经常这样做,想了解是否允许我使用内置的排序、搜索和比较函数(如下所示)来解决算法问题。

在编码面试中,我是否必须假装 Objective-c 没有排序、反转和其他实用程序?

或者一切都是公平的游戏,只要找到解决方案就可以了?

如果有更好的媒介来提出这个问题,请告诉我在哪里发布这个问题。

从这里: https: //rosettacode.org/wiki/Longest_increasing_subsequence#Objective-C

#import <Foundation/Foundation.h>

@interface Node : NSObject {
@public
  id val;
  Node *back;
}
@end

@implementation Node
@end

@interface NSArray (LIS)
- (NSArray *)longestIncreasingSubsequenceWithComparator:(NSComparator)comparator;
@end

@implementation NSArray (LIS)
- (NSArray *)longestIncreasingSubsequenceWithComparator:(NSComparator)comparator {
  NSMutableArray *pileTops = [[NSMutableArray alloc] init];
  // sort into piles
  for (id x in self) {
    Node *node = [[Node alloc] init];
    node->val = x;
    int i = [pileTops indexOfObject:node
                      inSortedRange:NSMakeRange(0, [pileTops count])
                            options:NSBinarySearchingInsertionIndex|NSBinarySearchingFirstEqual
                    usingComparator:^NSComparisonResult(Node …
Run Code Online (Sandbox Code Playgroud)

sorting algorithm objective-c data-structures

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

iOS RxSwift如何检查Result == .success?

我只对.success来自查询的类型的结果感兴趣。

如何设置过滤器以仅通过Result<Value>枚举的.success结果?

public enum Result<Value> {
    case success(Value)
    case failure(Error)
}


query.filter{ (result: Result<Double>) in
                switch result {
                case .success:
                    return true
                case .failure:
                    return false
                }
            }
Run Code Online (Sandbox Code Playgroud)

我只想对成功进行速记​​检查,但是编译器不允许这样做。

.filter{result in
    return result == .success
}
Run Code Online (Sandbox Code Playgroud)

enums reactive-programming ios swift rx-swift

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