小编Rea*_*son的帖子

hidesBarsOnSwipe for childView

我有以下(简化)层次结构:UINavigationController -> UIViewController -> UITableViewController.当我使用滚动我的tableview时,我想隐藏导航栏hidesBarsOnSwipe.现在发生的是每当我向下滚动时导航栏都会隐藏,但是当我向上滚动时它不会再出现.这就是我的代码:

// Create a navigation controller and set as root view controller
// Enable hidesBarsOnSwipe
UINavigationController *navigationC = [UINavigationController new];
self.window.rootViewController = navigationC;
navigationC.hidesBarsOnSwipe = YES;

// Create a view controller to act as parent for the table view
UIViewController *parentVC = [UIViewController new];
[navigationC pushViewController:parentVC animated:NO];

// Create the table view controller
UITableViewController *tableVC = [UITableViewController new];
tableVC.tableView.dataSource = self;

// Add the table view as a subview to the parent …
Run Code Online (Sandbox Code Playgroud)

uinavigationbar uitableview ios ios8

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

Objective-c/iOS:在异步函数中设置状态文本很慢

在我的应用程序中,我正在与远程服务器进行一些通信,因为这可能很慢,我认为以异步方式运行该代码是个好主意.我将通信代码放在一个块中,然后传递给dispatch_async.此代码执行通信,并在完成后设置标签的文本.最后一部分是问题所在.文本已设置,但会在延迟几秒后发生.这是我的代码.

- (void)doNetworkingTask {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Slow network task goes here.

        // Slow network task done, notify the user.
        [self.myLabel setText:@"task done."];
        NSLog(@"task done.");
    });
}
Run Code Online (Sandbox Code Playgroud)

这里发生的是我的网络任务完成,NSLog文本被记录,几秒钟后,标签的文本被更新.我的问题是1)为什么标签文字不会立即更新?2)做我想做的事的正确方法是什么?(执行慢速网络任务而不阻止任何其他任务,一旦完成,就通过文本标签更新用户.)

iphone objective-c ios

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

Objective C共享readonly类的实例

我想在Objective C中创建一个类的只读实例.我有一个向量类,基本上浮动x和y位置以及一些方法.在很多情况下我需要一个(0,0) - 向量,所以我想的是每次我都有一个共享的零向量而不是分配一个新的向量,如下所示:

// Don't want to do this all the time (allocate new vector)
compare(v, [[Vector alloc] initWithCartesian:0:0]);

// Want to do this instead (use a shared vector, only allocate once)
compare(v, [Vector zeroVector]);

// My attempt so far
+ (Vector *)zeroVector {
    static Vector *sharedZeroVector = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedZeroVector = [[self alloc] initWithCartesian:0:0];
    });
    return sharedZeroVector;
}

// The problem
v.x = 3;
Run Code Online (Sandbox Code Playgroud)

这样可以正常工作,除了零矢量不是只读,这感觉有点傻.作为一个说明,我想提一下,这更像是一个想要知道如何的问题,而不是一个实际的问题,我不知道它是否会产生一些实际的差异.

objective-c

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

(Kiss)XML xpath和默认命名空间

我正在开发一个需要解析一些xml的iPhone项目.xml可能包含也可能不包含默认命名空间.我需要知道如何解析xml以防它使用默认命名空间.因为我需要阅读一个写xml,我倾向于使用KissXML,但我愿意接受建议.

这是我的代码:

NSString *content = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]
    pathForResource:@"bookstore" ofType:@"xml"] encoding:NSUTF8StringEncoding error:nil];

DDXMLDocument *theDocument = [[DDXMLDocument alloc] initWithXMLString:content options:0 error:nil];

NSArray *results = [theDocument nodesForXPath:@"//book" error:nil];
NSLog(@"%d", [results count]);
Run Code Online (Sandbox Code Playgroud)

它在这个xml上按预期工作:

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
  <title lang="en">Everyday Italian</title>
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
</book>
</bookstore>
Run Code Online (Sandbox Code Playgroud)

但是当xml有一个命名空间时,它会停止工作:

<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns="[INSERT RANDOM NAMESPACE]">
<book category="COOKING">
  <title lang="en">Everyday Italian</title>
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
</book>
</bookstore>
Run Code Online (Sandbox Code Playgroud)

当然,我可以预处理字符串并删除xmlns,虽然这感觉就像是一种丑陋的黑客.处理这个问题的正确方法是什么?

xml xpath objective-c ios kissxml

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

标签 统计

ios ×3

objective-c ×3

ios8 ×1

iphone ×1

kissxml ×1

uinavigationbar ×1

uitableview ×1

xml ×1

xpath ×1