關於UIScrollView有些你很難知曉的崩潰情形

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

關於UIScrollView有些你很難知曉的崩潰情形

為了實現以下的功能(按鈕之間的轉場效果):

簡短的代碼如下:

////  RootViewController.m//  BUG////  Copyright (c) 2014年 Y.X. All rights reserved.//#import "RootViewController.h"@interface RootViewController (){    UIView    *_showView;}@end@implementation RootViewController- (void)viewDidLoad{    [super viewDidLoad];    _showView = [[UIView alloc] initWithFrame:self.view.bounds];    [self.view addSubview:_showView];        NSArray *title = @[@"YouXianMing",                       @"XianHui",                       @"XianMing",                       @"XianNeng",                       @"XianRen"];        [title enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {        // 初始化button        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 50*(idx + 1), 130, 30)];        button.layer.borderWidth = 1.f;        [_showView addSubview:button];                // 設定字型        button.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin"                                                 size:15.f];                // 設定標題以及標題顏色        [button setTitle:obj                forState:UIControlStateNormal];        [button setTitleColor:[UIColor redColor]                     forState:UIControlStateNormal];                // 添加事件        [button addTarget:self                   action:@selector(buttonsEvent:)         forControlEvents:UIControlEventTouchUpInside];    }];}- (void)buttonsEvent:(UIButton *)button{    [_showView.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {        UIButton *tmpButton = obj;                if ([tmpButton isEqual:button])        {            [tmpButton setTitleColor:[UIColor redColor]                            forState:UIControlStateNormal];        }        else        {            [tmpButton setTitleColor:[UIColor blackColor]                            forState:UIControlStateNormal];        }    }];}@end

之後,將UIView替換成UIScrollView後:

然後就會崩潰-_-!!

崩潰資訊:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException‘, reason: ‘-[UIImageView setTitleColor:forState:]: unrecognized selector sent to instance 0xa590390‘

崩潰原因是_showView.subviews裡面有一個UIImageView

我們並沒有添加這個東西UIImageView到subviews中呢,其實,這個東西是UIScrollView自己的一個東西......

寫上以下保護性語句就沒問題了.

話說,UIScrollView跟你偷偷加了點東西讓你崩潰了都不知道咋回事-_-!!!

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.