0

私は本当にこれが前に尋ねられなかったことを望みます。私はこのサイトで解決策を探すのにかなりの時間を費やしましたが、解決策を思い付くことができませんでした。callPerformSegueという関数からperformSegueWithIdentifierを呼び出そうとしています。callPerformSegueは、UITableViewのセクションのフッターにあるUIImageViewがクリックされたときに呼び出されます。callPerformSegue関数は次のとおりです。

- (void)callPerformSegue {
    [self performSegueWithIdentifier:@"bannerPressed" sender:self];
} 

ストーリーボードでbannerPressedセグエが正しく識別されています。これは、performSegueWithIdentifier呼び出しをdidSelectRowAtIndexPathに移動すると、セグエが正しく実行されるためです。ただし、callPerformSegueから呼び出されると、次のようになります。

'NSInvalidArgumentException'、理由:'受信者(****)に識別子'bannerPressed''のセグがありません

何か案は?

アップデート:

UIImageViewのサブクラスであるBannerViewクラスから関数callPerformSegueを呼び出します。このクラスは、誰かがバナーをクリックしたときのタッチイベントを処理し、タッチが受信されたときに表示された画像を判別します。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //Get the time of the click
    NSDate *animationStart;
    NSDate *clickTime;
    clickTime = [NSDate date];

    NSMutableArray *bannerArrayFromDictionary = [self.bannerDictionary objectForKey:[NSNumber numberWithInt:self.currentSection]];

    //Calculate the time elapsed since animationStart and clickTime
    animationStart = [bannerArrayFromDictionary objectAtIndex:0];

    int secondsElapsed = [clickTime timeIntervalSinceDate:animationStart];

    //Determine the number of elements for the section
    int numberOfImagesForSection = [bannerArrayFromDictionary count] - 1;

    //Determine the index into the animationArrary
    int imageClickedIndex = (secondsElapsed / 5) % numberOfImagesForSection;

    //Add 1 to the index to compensate for the timestamp
    imageClickedIndex++;

    //Get the image name
    NSString *clickedImage = [bannerArrayFromDictionary objectAtIndex:imageClickedIndex];

    //Set the image name in CategoryViewController so that a segue to the Detail Page can be performed
    CategoryViewController *view = [[CategoryViewController alloc] init];
    view.currentImage = clickedImage;
    [view callPerformSegue];

}
4

2 に答える 2

2

BannerView.h

@property (strong,nonatomic) IBOutlet id  delegate;

BannerView.m

[self.delegate callPerformSegue];

CategoryViewController.m

bannerView.delegate = self;
于 2012-05-28T12:43:45.770 に答える
1

Segueは、ViewControllerではなくTableViewセルに接続されている可能性があります。私は、セグエをボタンやTableViewセルではなく、常にVCに接続することを習慣にしています。修正するには、現在使用しているSegueを削除し、TableViewセルではなくVCに再配線します。必ず同じ名前を付けてください。

于 2012-05-28T12:21:50.200 に答える