我有一個類,其子類UITableViewController
。根據此類中識別的用戶操作,我需要在表中實例化UIViewController
時調用表中的方法。我無法弄清楚如何做到這一點。不同類別的調用方法
我試圖讓這個函數成爲靜態的,但是這不起作用,因爲有一個我需要的實例變量。我大概可以使用NSNotificationCenter
,但我的直覺是有更好的方法。有人可以幫忙嗎?謝謝!
MonthsTableViewController.h
@interface MonthsTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
{
NSArray *monthsArray;
}
@end
MonthsTableViewController.m
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"calling the UIViewController");
//this is where I am stuck!!!
}
SubscribeViewController.h
@interface SubscribeViewController : UIViewController <SIMChargeCardViewControllerDelegate>
{
MonthsTableViewController *monthsController;
IBOutlet UITableView *monthsTable;
}
- (void) snapMonthsToCenter;
@end
SubscribeViewController.m
- (void) snapMonthsToCenter {
// snap the table selections to the center of the row
NSLog(@"method called!");
NSIndexPath *pathForMonthCenterCell = [monthsTable indexPathForRowAtPoint:CGPointMake(CGRectGetMidX(monthsTable.bounds), CGRectGetMidY(monthsTable.bounds))];
[monthsTable scrollToRowAtIndexPath:pathForMonthCenterCell atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
發送通知或定義在'MonthsTableViewController'的協議和委託。然後'MonthsTableViewController'可以告訴它的代表發生了什麼事。 SubscriberViewController可以是委託。當調用委託方法時,'SubscribeViewController'可以調用它自己的'snapMonthsToCenter'或其他任何需要做的事情。 – rmaddy 2014-10-02 03:26:21