没有访问委托方法

时间:2012-01-13 03:36:44

标签: iphone ios uitableview delegates

我正在使用委托将一些信息从一个视图传递到另一个视图,但是当我选择一个tableview单元格时,我将数据传递给委托,该委托将信息传递回堆栈上的视图..它会使其返回到视图但实际上并没有在视图改变时进入委托方法...

这是我设置代表的地方。

subViewController.h

#import <UIKit/UIKit.h>

@protocol PassSubSearchData <NSObject>
@required
- (void) setModSearchFields:(NSArray *)modArray modIndexPath:(NSIndexPath *)modIndexPath setSubMod:(NSArray *)subModArray subModIndexPath:(NSIndexPath *)subModIndexPath;
@end

//...

//Delegate for passing Model and SubModel data back to VehicleSearchViewController
    id <PassSubSearchData> delegate;

//...

//Delegate for passing Model and SubModel data back to VehicleSearchViewController
@property (strong) id delegate;

//这就是我使用它的方式

subViewController.m

#import "MainViewController.h"
#import "SubViewController.h"

@implementation VehicleSubResultViewController


//...

//Delegate for passing Model and SubModel data back to VehicleSearchViewController
@synthesize delegate;

//...

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Access selected cells content (cell.textLabel.text)
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    //Predicates restrict the values that will be returned from the query
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"SUB",cell.textLabel.text];
    filterArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate];


    [[self delegate] setModSearchFields:tempModArray modIndexPath:tempModIndexPath setSubMod:filterArray subModIndexPath:indexPath];

    //This pops to the VehicleSearchViewController view
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

}

然后在主视图中

MainViewController.h

#import "SubViewController.h"

@interface VehicleSearchViewController : UITableViewController <PassSubSearchData> {
//...

MainViewController.m //但是从未访问过这部分代码

- (void) setModSearchFields:(NSArray *)modArray modIndexPath:(NSIndexPath *)modIndexPath setSubMod:(NSArray *)subModArray subModIndexPath:(NSIndexPath *)subModIndexPath
{
    modObjectString = [[modArray valueForKey:@"MOD"] objectAtIndex:0];
    modIndexPath = modIndexPath; // Sets the selected IndexPath from the subview

    subModObjectString = [[modelArray valueForKey:@"SUBMODEL"] objectAtIndex:0];
    subModIndexPath = subModResultIndexPath; // Sets the selected IndexPath from the subview

    NSLog(@"%@", modObjectString);
    NSLog(@"%@", modIndexPath);
    NSLog(@"%@", subModObjectString);
    NSLog(@"%@", subModIndexPath);


    [self.tableView reloadData]; 
}

就这样,如果有人知道任何帮助,我只是不确定我错过了什么。

1 个答案:

答案 0 :(得分:4)

代表很可能从未设置过,所以它是零,没有任何反应。