小编Mee*_*shi的帖子

在呈现模态视图控制器之后推动导航控制器

我有一个标签视图控制器,它有一个像这样的按钮,当它被按下时,会出现一个模态:

PostViewController *post = [[PostViewController alloc] init];

// [self.navigationController pushViewController:post animated:YES];

// Presentation
[self presentViewController:post animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

当模态完成后,我想解除它并推送一个新的视图控制器,如下所示:

ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[self.navigationController pushViewController:profile animated:YES];
Run Code Online (Sandbox Code Playgroud)

但我不能在后vc作为它的模态.我该怎么做呢?

uiviewcontroller uinavigationcontroller uitabview ios

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

iPhone - 内存泄漏 - NSData dataWithContentsOfUrl和UIWebView

请帮忙!一直盯着这个12个小时; 并已在线查找,无法找到解决方案.

在我的应用程序中,我在单独的页面/控制器中使用2个UIView控件:

  • UIImageView(通过NSData dataWithContentsOfUrl检索数据)
  • UIWebView的

为了隔离我的代码,并使其更容易解释,我创建了一个名为"MyTestApplication"的基于视图的新项目

1 - 我在委托函数中添加了一个简单的NSData dataWithContentsOfUrl.

NSData *imageData = [NSData dataWithContentsOfURL:
  [NSURL URLWithString:@"http://www.google.com/intl/en_ALL/images/logo.gif"]];
Run Code Online (Sandbox Code Playgroud)

(由于它全部使用便利功能,因此无需在此发布)

替代文字http://img.skitch.com/20081110-j5tn5n7ixph95ys4rpchibaw5p.preview.jpg

看图

2 - 运行它以验证没有泄漏(如预期的那样)

替代文字http://img.skitch.com/20081110-fy2qrkgy47hm4fe2f1aakd4muw.preview.jpg

看图

3 - 打开ViewController.xib,只需从库中添加一个UIWebView(无需连线)

替代文字http://img.skitch.com/20081110-d63c3yh1a1kqiciy73q8uyd68j.preview.jpg

看图

4 - 运行它以验证是否有泄漏!(为什么???)

替代文字http://img.skitch.com/20081110-qtxcfwntbcc3csabda3r6nfjg6.preview.jpg

看图

我究竟做错了什么?请帮忙!

如果我使用UIWebView,为什么NSData会导致内存泄漏?我只是不明白.谢谢.

iphone cocoa-touch memory-leaks objective-c ios

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

动画UITextField时的奇怪行为

我正试图制作动画,UITextField但我被一个恼人而奇怪的问题所困扰.我的动画有以下顺序:

第一个州

在第一种状态下,应用程序具有UITextField相机UIButton和取消UIButton后未显示的相机按钮,因为它已被定位在应用程序的限制范围之外.实际上我的应用程序有320的宽度和取消按钮来源是(350,7)

第二州

在第二状态中,当用户触摸时UITextField,相机按钮alpha通道被设置为0并且取消按钮的原点被设置为(247,7).

最终状态

用户触摸键盘的返回按钮或取消按钮后,最终状态与第一状态相同.

在处理期间,UITextField宽度和x轴上的取消按钮原点是动画的.

我的代码是:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
  barcodeSearchButton.userInteractionEnabled = NO;
  cancelButton.userInteractionEnabled = NO;

   CGFloat cancelButtonXOffset = CGRectGetMaxX(barcodeSearchButton.frame) - cancelButton.frame.size.width;
   CGFloat searchFieldWidth = searchField.frame.size.width - cancelButton.frame.size.width + barcodeSearchButton.frame.size.width;
   [UIView animateWithDuration:0.3
         animations:^{
             searchField.frame = CGRectMake(searchField.frame.origin.x, searchField.frame.origin.y, searchFieldWidth, searchField.frame.size.height);
             cancelButton.alpha = 1.0;                
             cancelButton.frame = CGRectMake(cancelButtonXOffset, cancelButton.frame.origin.y, cancelButton.frame.size.width,cancelButton.frame.size.height);

             barcodeSearchButton.alpha = 0.0;

         }
         completion:^(BOOL finished) {
             barcodeSearchButton.userInteractionEnabled = NO;
             cancelButton.userInteractionEnabled = YES;
         }];    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
  barcodeSearchButton.userInteractionEnabled = NO;
  cancelButton.userInteractionEnabled …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uiviewanimation ios4 ios

5
推荐指数
2
解决办法
3132
查看次数

为什么使用setViewControllers从UINavigationController的导航栏中删除所有内容?

这是问题所在.我在a中使用以下代码UINavigationController来交换rootViewController.我需要能够rootViewController在多个不同的屏幕之间进行交换,并允许用户从每个屏幕向下钻取(这显然是我需要导航控制器的原因):

SomeViewController *tmp = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
NSArray * viewControllers = [self viewControllers];
NSArray * newViewControllers = [NSArray arrayWithObjects:tmp, nil];
[self setViewControllers:newViewControllers];
Run Code Online (Sandbox Code Playgroud)

现在在阅读类参考时,UINavigationController我看到对于"viewControllers"属性,它说:"根视图控制器在数组中的索引0处,后视图控制器在索引n-2处,并且顶部控制器是在索引n-1处,其中n是数组中的项目数."

当我在那里打印我的viewControllers数组的计数时,我得到1,当前的rootViewController.如果顶级控制器(我假设是导航栏)没有东西吗?

一旦我使用setViewControllers新视图,导航栏中的所有内容都会消失.我将添加我有一个左右按钮以及一个自定义标题按钮,它们都已初始化并添加到init方法的导航栏中,并且一直工作正常,直到它们消失在我身上.

任何帮助将不胜感激.

xcode objective-c uiviewcontroller uinavigationcontroller ios

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

无法在UIPopover的UINavigationController侧调整UIViewController的高度contentSizeForViewInPopover

我用UINavigationController里面UIPopoverController

-(void)showEditMenuFrom:(UIButton *)button{
    if (self.popover) {
        [self.popover dismissPopoverAnimated:YES];
        self.popover = nil;
    }
    else {
        EditMenuViewController *editMenuViewController = [[EditMenuViewController alloc] initWithNibName:@"EditMenuViewController" bundle:nil];

        UINavigationController *actionsNavigationController = [[UINavigationController alloc] initWithRootViewController:editMenuViewController];
        actionsNavigationController.delegate = self;

        // switch for iPhone and iPad.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            self.popover = [[UIPopoverController alloc] initWithContentViewController:actionsNavigationController];
            self.popover.delegate = self;
            //            CGRect presentFrame = CGRectMake(button.frame.origin.x-43, button.frame.origin.y-10, button.frame.size.width, button.frame.size.height);
            [self.popover presentPopoverFromRect:button.frame inView:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        } else {
            [self presentViewController:actionsNavigationController animated:YES completion:^{
                NSLog(@"Activity complete");
            }];
        }
    }

    } …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller ios uipopover

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

UIWebView scrollView.contentSize.height 没有改变

加载 htmlString 后,scrollView 的 contentSize 不变UIWebView。在其他我的 viewControllers 都很好,但现在有点神秘

我有

UIWebView *contentWebView;
Run Code Online (Sandbox Code Playgroud)

我用某种方法做到了

- (void)makeContent
{
    ...
    contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(5, imageView.originY + imageView.height + 5, mainView.width - 10, 100)];
    contentWebView.delegate = self;
    contentWebView.scrollView.scrollEnabled = NO;
    contentWebView.contentMode = UIViewContentModeScaleAspectFit;
    NSLog(@"%@", factDict[@"text"]);
    [contentWebView loadHTMLString:factDict[@"text"] baseURL:nil];
    contentWebView.height = contentWebView.scrollView.contentSize.height;
    [mainView addSubview:contentWebView];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"%f %f %f %f ", webView.height, webView.scrollView.contentSize.height, contentWebView.height, contentWebView.scrollView.contentSize.height);
    [webView sizeToFit];
    NSLog(@"%f %f %f %f ", webView.height, webView.scrollView.contentSize.height, contentWebView.height, contentWebView.scrollView.contentSize.height);
...
}
Run Code Online (Sandbox Code Playgroud)

早期的其他控制器contentWebView.height …

objective-c uiwebview ios

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

偶尔ios MKMapView在转到其他屏幕时会崩溃并重新回到MapScreen

在我的IOS App中,我将Map包含的视图控制器声明为共享实例.

Exception Type:  EXC_BAD_ACCESS (SIG SEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000028
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread

Thread 0 Crashed:

0   VectorKit                       0x37058b86 __64-[VKMapCanvas 
animateToMapRegion:pitch:yaw:duration:completion:]_block_invoke_0168 + 50

1   VectorKit                       0x37003bee -[VKAnimation _stopAnimation:] + 38

2   VectorKit                       0x36fcd4a8 -[VKAnimation onTimerFired:] + 48

3   VectorKit                       0x36fcd2d0 -[VKMainLoop displayTimerFired:] + 352

4   QuartzCore                      0x3ab6706c

CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) + 156

5   QuartzCore                    0x3ab66fc4 CA::Display::IOMFBDisplayLink::callback(__ IOMobile Frame buffer*, unsigned long long, unsigned long long, unsigned long long, void*) …
Run Code Online (Sandbox Code Playgroud)

iphone crash objective-c mkmapview ios

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

如何在Swift中将gif显示到UIImageView中?

我想在UIImageView中使用gif,但我不能.我的代码是:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"gif"];
    UIImage *testImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
    self.dataImageView.animationImages = testImage.images;
    self.dataImageView.animationDuration = testImage.duration;
    self.dataImageView.animationRepeatCount = 1;
    self.dataImageView.image = testImage.images.lastObject;
    [self.dataImageView startAnimating];
}
Run Code Online (Sandbox Code Playgroud)

迅速:

var url : NSURL = NSBundle.mainBundle().URLForResource("MAES", withExtension: "gif")
Run Code Online (Sandbox Code Playgroud)

在目标CI中有animatedImageWithAnimatedGIFData,但在swift中我不知道如何调用此或如果不存在..

谢谢!

animation gif swift ios8

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

从NSArray中删除对象

如何从反转中删除对象NSArray.

目前我有一个NSMutableArray,然后我反过来

NSArray* reversedCalEvents = [[calEvents reverseObjectEnumerator] allObjects];
Run Code Online (Sandbox Code Playgroud)

现在我需要从项目中删除reversedCalEventscalEvents自动刷新数组根据条件显示的表.即

if(someInt == someOtherInt){
    remove object at index 0
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我无法让它发挥作用.

objective-c uitableview nsmutablearray nsarray ios

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

在iOS中的UITableViewCell中,setHighlighted和setSelected有什么区别?

之间有什么区别setHighlightedsetSelectedUITableViewCell

如果我只想cell在选择时不突出显示,我应该覆盖setHighlighter还是只设置selectionStyleNONE.

objective-c uitableview tableviewcell ios

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