0
我必須顯示一個自定義iOS 7樣式的警報請求者與中心中的一組自定義按鈕(類別過濾器切換具體)。爲此,我在GitHub上找到了優秀的SDCAlertView。我的方法是創建一個自定義UIViewController
,它處理按鈕和按鍵觸摸的創建,實例化,然後插入警報的contentView
這樣的:SDCAlertView和UIViewController與UIButton
SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Filter"
message:nil
delegate:self
cancelButtonTitle:@"Clear"
otherButtonTitles:@"Filter", nil];
GKSecondViewController *vc = [[GKSecondViewController alloc] init];
UIView *view = vc.view;
[alert.contentView addSubview:view];
[view sdc_centerInSuperview];
[alert.contentView sdc_pinHeight:100];
[alert.contentView sdc_pinWidth:100];
[alert.contentView setBackgroundColor:[UIColor redColor]];
[alert show];
我的視圖控制器(GKSecondViewController
)看起來是這樣的:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self.view setBackgroundColor:[UIColor grayColor]];
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view sdc_pinHeight:100];
[self.view sdc_pinWidth:100];
UIButton *button = [[UIButton alloc] init];
[button setTitle:@"Button" forState:UIControlStateNormal];
[button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]];
[button setTranslatesAutoresizingMaskIntoConstraints:NO];
[button sdc_pinHeight:100];
[button sdc_pinWidth:100];
[self.view addSubview:button];
[button sdc_centerInSuperview];
}
return self;
}
- (void)tap:(UIGestureRecognizer *)gesture
{
gesture.view.backgroundColor = [UIColor blackColor];
}
(您也可能需要SDCAutoLayout。)當我單擊警報中的按鈕時,它在跟蹤日誌中沒有任何提示而崩潰。我錯過了什麼或做錯了什麼?