小编Pun*_*rma的帖子

didMoveToParentViewController调用了两次

我做了一个简单的测试,以了解更多有关包含视图控制器
我有一个视图控制器,我使用两个按钮的动作添加/删除了一个视图控制器:


- (IBAction)myInfoAddAction:(id)sender {
    profileViewController = [[ProfileViewController alloc] init];
    [self addChildViewController: profileViewController];
    UIView *__view = profileViewController.view;
    [self.view addSubview: __view];
    [profileViewController didMoveToParentViewController: self];
}

- (IBAction)myInfoRemoveAction:(id)sender {
    [profileViewController willMoveToParentViewController: nil];
    [profileViewController.view removeFromSuperview];
    [profileViewController removeFromParentViewController];
}
Run Code Online (Sandbox Code Playgroud)

ProfileViewController扩展UIViewController和覆盖willMoveToParentViewController以及didMoveToParentViewController方法


-( void)willMoveToParentViewController:(UIViewController *)parent
{
    [super willMoveToParentViewController: parent];
    NSLog(@"willMoveToParentViewController -> %@", self);
}

-( void) didMoveToParentViewController:(UIViewController *)parent
{
    [super didMoveToParentViewController: parent];
    NSLog(@"didMoveToParentViewController -> %@", self);
}

-( void)viewWillAppear:(BOOL)animated
{
    NSLog(@"viewWillAppear -> %@", self);
}

-( void)viewDidDisappear:(BOOL)animated
{ …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller ios

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

ios8 UIImage imageNamed:崩溃

我遇到了一个崩溃的UIImage imageNamed:方法中列出的奇怪的崩溃.此崩溃仅出现在iOS8上,对许多用户来说都是一个持续存在的问题.虽然,奇怪的是我在测试时无法重现这个问题.

请参阅crashlytics的崩溃日志图片. 在此输入图像描述

我想,这可能需要对imageNamed:方法的内部工作做些什么.

iphone objective-c uiimage ios ios8

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

iOS推送通知问题

我正在做一个推送通知功能是其中一个关键功能的项目.
当我在应用程序中时它工作正常,我收到通知并处理该通知.

但问题是当我在后台并且通知收到我在我的应用程序图标上看到徽章时,当我点击图标我的应用程序正在启动但该didReceiveRemoteNotification方法未被调用,因此我无法处理该通知.

另一个问题是有时它显示通知消息,device notification list有时则没有.

当我通过点击通知列表项目进入我的应用程序时,我didReceiveRemoteNotification可以成功处理通知.我在下面编写代码didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method

NSDictionary* remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif != nil)
{
    NSLog(@"didFinishLaunchingWithOptions\nNotification recieved:\n%@",remoteNotif);

    notificationData=[[NSDictionary alloc]initWithDictionary:remoteNotif];
    [notif saveNotification:remoteNotif];
}
Run Code Online (Sandbox Code Playgroud)

帮我解决这个问题.提前致谢.

iphone push-notification apple-push-notifications ios

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

动态TextView与故事板和自动布局

我有一个视图,其中包含UITextView一系列其他视图.我们的想法是调整文本视图的内容大小,并向上移动所有其他视图.

我在storyboard中设置了所有约束,如果我从那里更改TextView的高度约束值,则所有视图都会更新.

在运行时,我可以调整文本视图框架的大小以适应它的内容大小,但视图的其余部分不会更改.所以我猜我不必更改框架而只需更改高度约束.

关于如何在运行时做这件事的任何建议?如何更改代码中的高度约束值?有没有办法从故事板中将约束"链接"到控制器?

谢谢你的帮助

constraints storyboard textview ios autolayout

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

为什么在主队列上调用 dispatch_sync() 会阻塞主队列?

我知道这不是一个强烈的问题,但我必须明确这个概念。

我定义myBlock如下。

void(^myBlock)(void) = ^{
   for(int i = 0;i < 10 ; i++)
   {
       NSLog(@"%d and current queue = %@",i,[NSThread currentThread]);
   } 
};
Run Code Online (Sandbox Code Playgroud)

现在在viewDidLoad方法中,当我dispatch_sync()在主队列上独立使用该方法时,主队列被阻塞。

这是示例。

- (void)viewDidLoad
 {
    [super viewDidLoad];
    dispatch_queue_t queue = dispatch_get_main_queue();
    dispatch_sync(queue,myBlock);
 }
Run Code Online (Sandbox Code Playgroud)

但是,当我dispatch_sync()在主线程上使用相同的函数dispatch_async()在并发队列上触发的函数块内时,主线程不会被阻塞。

这是示例。

- (void)viewDidLoad
 {
    [super viewDidLoad];
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_async(queue,^{  

        dispatch_sync(dispatch_get_main_queue(),myBlock);
    });
 }
Run Code Online (Sandbox Code Playgroud)

我不清楚为什么会这样?为什么dispatch_sync()独立调用时主线程被阻塞?

iphone multithreading ios

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

在具有多个笔尖的UITableViewCell中动态获取行高

我有一个UITableViewUITableViewCell来自不同的笔尖文件加载当用户轻敲或双抽头的小区,即,有不同高度的三个不同的笔尖文件,每一个用于正常,抽头和双击.

如何识别加载的笔尖heightForRowAtIndexPath:以动态设置行高?

uitableview nib ios ios6

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

如何在数组中保存自定义对象并将其存储在NSUserDefaults - iPhone中

我在按钮操作方法后获取自定义类对象.现在我需要存储多个自定义对象NSMutableArray,然后将此数组存储在其中NSUserDefaults.

这是我的代码:

-(IBAction)onClickSubmitLater:(id)sender
{
    //Saving store in user defaults for later upload data.

    NSMutableArray *arrayStoreList = [[NSMutableArray alloc] init];
    arrayStoreList = [Util getArrayPreference:@"Store"];//arrayStoreList is the list of all stores.

    Store *store = [[Store alloc] init];
    store = [arrayStoreList objectAtIndex:self.selectedStoreIndex];//here i am getting particular store that i need to save in array.

    //archive
    NSData *dataStore = [NSKeyedArchiver archivedDataWithRootObject:store];
    [[NSUserDefaults standardUserDefaults] setObject:dataStore forKey:@"resultStore"];

    //unarchive
    NSData *dataResultStore = [[NSUserDefaults standardUserDefaults] objectForKey:@"resultStore"];

    Store *resultStore = (Store *)[NSKeyedUnarchiver unarchiveObjectWithData:dataResultStore];
    NSLog(@"%@", resultStore); …
Run Code Online (Sandbox Code Playgroud)

arrays objective-c nsuserdefaults ios

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