1
我使用的是iCarousel,我在其中顯示一些按鈕。但是,如果點擊按鈕,我怎麼能到另一個視圖?如何從iCarousel中的按鈕創建一個segue到另一個視圖
我有這樣的代碼已經:
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return 10;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIButton *button = (UIButton *)view;
if (button == nil)
{
UIImage *image = [UIImage imageNamed:@"page.png"];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setBackgroundImage:image forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}
return button;
}
- (void)buttonTapped:(UIButton *)sender
{
NSInteger index = [carousel indexOfItemViewOrSubview:sender];
//Action
}
我如何去當按鈕被竊聽另一種觀點?我也可以在這裏使用prepareForSegue方法嗎?
感謝您的幫助!
非常感謝您的工作得很好,但您可能表示的方法是performSegueWithIdentifier。 :) –
哦,你是對的..我從來沒有在Xcode中嘗試過這些,我只是寫了它。我甚至仔細閱讀了幾遍,以確保我沒有得到任何錯誤。哦,好吧.. :)雖然接近。很高興我能幫上忙! – Sti