委托不响应选择器

时间:2015-11-11 03:10:58

标签: ios objective-c

我想将一个NSInteger从tableViewController(HistoryTableViewController)传递到另一个viewController(InformationViewController),但显然它没有响应我的选择器。

HistoryTableViewController.h:

@class HistoryTableViewController;

@protocol HistoryTableViewControllerDelegate <NSObject>
- (void)addItemViewController:(HistoryTableViewController *)controller passItem:(NSInteger *)rowNum;
@end

@interface HistoryTableViewController : UITableViewController {
    NSInteger row;
}

@property (nonatomic, weak) id <HistoryTableViewControllerDelegate> delegate;

@end

HistoryTableViewController.h

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    row = [self.tableView indexPathForSelectedRow].row;
   }

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"informationSegue"]) {
   if([self.delegate respondsToSelector:@selector(addItemViewController:passItem:)]){
         [self.delegate addItemViewController:self passItem:&(row)];
        }
    }
}

InformationViewController.h:

@interface InformationViewController : UIViewController <HistoryTableViewControllerDelegate>
@property (nonatomic, assign) NSInteger rowIn;

InformationViewController.m

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"informationSegue"]) {
    HistoryTableViewController *historyvc = segue.destinationViewController;
    historyvc.delegate = self;
    }
}

- (void) addItemViewController:(HistoryTableViewController *)controller      passItem:(NSInteger *)rowNum {
    rowIn = *rowNum;
}

&#34; informationSegue&#34;是我的segueIdentifier从HistoryTableViewController到InformationViewController。

1 个答案:

答案 0 :(得分:0)

我实际上自己找到了答案。我正在使用代码将委托传递回另一个视图控制器,但我应该在视图控制器之间向前传递委托