我在UIScrollView
在StoryBoard
編程方式添加的按鈕越來越崩潰的故事板
下面添加一個按鈕是我使用的代碼。
-(void)addScrollView
{
for(int i=0;i<[array count];i++)
{
UIScrollView *subScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 400, SUBSCROLLVIEW_WIDTH, SUBSCROLLVIEW_HEIGHT)];
UITextView *txtVwDetail = [[UITextView alloc] initWithFrame:CGRectMake(342, 0, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT)];
txtVwDetail.text = SAMPLE_STRING;
[self addSubScrollView:subScrollView];
[self.view addSubview:subScrollView];
[self.view addSubview:txtVwDetail];
}
}
-(void)addSubScrollView:(UIScrollView *)aSubScrollView
{
for(int i=0;i<[array count];i++)
{
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(intBtnX, (aSubScrollView.frame.size.height - 80)/2, 50, 80);
[aButton setImage:[UIImage imageNamed:[self.items objectAtIndex:i]] forState:UIControlStateNormal];
**[aButton addTarget:self action:@selector(btnSubImageClicked) forControlEvents:UIControlEventTouchUpInside];**
aSubScrollView.contentSize = CGSizeMake(intScrollViewWidth, aSubScrollView.frame.size.height);
[aSubScrollView addSubview:aButton];
}
}
在addSubScrollView
方法我已經添加的按鈕和這是越來越墜毀其click事件。
-(void)btnSubImageClicked
{
NSLog(@"btnSubImageClicked");
}
我遇到的情況是
MyMainViewController
是sourceViewController
爲我創造customSegue
這是UIStoryboardSegue
類
MyMainViewController
有一個UIView爲PlaceHolderView
在我加入MydestinationViewContoller
「觀是此滾動查看
-(void)perform
{
BrowseScreenVC *srcObj = (BrowseScreenVC *)[self sourceViewController];
UIViewController *dstObj = (UIViewController *)[self destinationViewController];
for(UIView *vw in srcObj.viewPlaceHolder.subviews)
{
[vw removeFromSuperview];
}
NSLog(@"dest : %@",dstObj.view);
NSLog(@"destobj :%@",dstObj);
srcObj.currentViewController = dstObj;
[srcObj.viewPlaceHolder addSubview:[dstObj.view retain]];
}
UPDATE
有了答案,我也不得不改變線路 srcObj.currentViewController = dstObj;
到
srcObj.addChildViewController = dstObj;
,使其工作
崩潰時控制檯中的錯誤消息是什麼? –
你能看到模擬器中的按鈕嗎? – Krunal
*** - [MyViewController performSelector:withObject:withObject:]:發送到解除分配實例的消息0x6a7f2e0 – Heena