小编mal*_*aba的帖子

未调用UINavigationControllerDelegate方法(github上的演示代码)

弹出到不支持当前方向的视图控制器时未调用的UINavigationControllerDelegate方法.

我有一个UINavigationController作为我的应用程序的根视图控制器(我的Storyboard中的初始视图控制器).

假设我将ViewController A推送到方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)

因此,我们不支持任何横向模式.最重要的是,让我们用另一个代码推送另一个ViewController:

@interface B : UIViewController <UINavigationControllerDelegate>
@end

@implementation B
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;   // any orientation supported
}

- (void)viewDidLoad {
    [super viewDidLoad];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UINavigationController *nc = (UINavigationController*)appDelegate.window.rootViewController;
    nc.delegate = self;
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // not always called...
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // not always called...
}
@end
Run Code Online (Sandbox Code Playgroud)

现在,如果我有我的iPhone在纵向和我推A的顶视图控制器B,通过一些触摸事件,然后点击导航条上的"返回"按钮,一切都很好,并委托方法被调用(我做一些东西有).

但是,如果,当我正在查看视图B时,我旋转到横向,然后点击后退按钮,那些委托方法不会被调用!! 如果有时调用方法而不调用其他方法,那么为UINavigationController设置委托有什么意义呢?当然,我做错了什么.

我尝试将委托放在其他类中,如AppDelegate或我的MainView,没有任何变化. …

cocoa-touch delegates uinavigationcontroller

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

如何使用RestKit映射XML textContent?

我有这样的XML:

<rss>
<channel>
 <item>
  <title>something</title>
  <description>...</description>
  <category>cooking</category>
  <category>housing</category>
 </item>

 <item>
  ...
 </item>
 ...
</channel>
</rss>
Run Code Online (Sandbox Code Playgroud)

它是一个RSS Feed,在一个频道内有一系列项目,包含许多标签/属性(标题,内容,......),以及一组类别标签.

我可以使用RestKit为频道/项目/标题/内容部分解析它:

RKManagedObjectMapping *itemMapping = [RKManagedObjectMapping mappingForClass:[Item class] inManagedObjectStore:objectStore];
[itemMapping mapKeyPath:@"title" toAttribute:@"title"];
[itemMapping mapKeyPath:@"description" toAttribute:@"content"];

RKManagedObjectMapping *channelMapping = [RKManagedObjectMapping mappingForClass:[Channel class] inManagedObjectStore:objectStore];
[channelMapping mapKeyPath:@"item" toRelationship:@"items" withMapping:itemMapping];

[manager.mappingProvider setMapping:channelMapping forKeyPath:@"rss.channel"];
Run Code Online (Sandbox Code Playgroud)

但我迷失了地图类别......我尝试过类似的东西:

RKManagedObjectMapping *categoryMapping = [RKManagedObjectMapping mappingForClass:[Category class] inManagedObjectStore:objectStore];
[itemMapping mapKeyPath:@"category" toRelationship:@"categories" withMapping:CategoryMapping]
Run Code Online (Sandbox Code Playgroud)

但不知何故,标签内的文本内容未映射到Category类中的属性'name'.我肯定没有在这里的代码中使用这个"名称",因为我不知道在哪里放它.

如何使用RestKit解析纯文本XML标记?是否有类似的东西:

[categoryMapping mapKeyPath:@".text" toAttribute:@"name"];
Run Code Online (Sandbox Code Playgroud)

(不起作用)

xml cocoa-touch ios restkit

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

使用块和ARC进行内存管理,泄漏?

我需要知道我是否正确地做到了.应用程序运行正常但我不确定我的生命周期是否正确(泄漏?).

注意:仪器看不到泄漏.

方法aaa的代码:某些类A的代码:

- (void) aaa {
   NSString *path = ...something...;

   NSBlockOperation* theOp = [NSBlockOperation blockOperationWithBlock: ^{
   // using path
   [self somethingElseWith:path];
   }];

   [self.aQueue addOperation:theOp];
}
Run Code Online (Sandbox Code Playgroud)

所以我创建了一个块来放置aQueue(NSOperationQueue*).目标是从主线程中卸载长时间运行的somethingElseWith:方法,以便GUI继续响应.

在块内部,我引用了aaa:方法末尾超出范围的本地var"path".

如果我正确地阅读了文档,那么该块将在'path'上保留.但ARC是否隐含地在此块的末尾插入了一个版本?这将是合乎逻辑和美好的.

或者我应该将'path'声明为__block并在块的末尾将其指定为nil?(手册...)

我不确定我是否理解如何在此上下文中使用__weak.

cocoa cocoa-touch objective-c objective-c-blocks automatic-ref-counting

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