我正在此錯誤無法識別的選擇器,委派問題
[ResultViewController setSearchFields:IndexPath:]:無法識別的選擇發送到實例0xc448840
我具有其中我使用導航控制器堆委託將信息傳遞迴導航堆棧中的前一個視圖。但是,我認爲我在聲明委託時出錯了。
我的導航堆棧看起來像這樣。
view 0 (mainmenu)
-- view 1 (SearchViewController)
--- view 2 (ResultViewController) - where I set the delegate of the new view being loaded
---- View 3 (SubViewController) - this is where my delegates reside
什麼我做的是彈出來VIEW1並通過這樣做,我得到這個錯誤但是通過委託信息這一觀點......我想,如果我必須設置委託視圖3視圖1我最終傳遞了這些信息......是否正確?
如果是這樣,在設置委託時我需要考慮什麼?我該如何把它從視圖1
這是我如何SubViewController
建立我的委託subvc.h
@protocol PassSubSearchData <NSObject>
@required
- (void) setSearchFields:(NSArray *)modArray IndexPath:(NSIndexPath *)modIndexPath;
@end
@interface VehicleSubResultViewController : UITableViewController <NSXMLParserDelegate> {
//..
//Delegate for passing Mod and SubMod data back to VehicleSearchViewController
id <PassSubSearchData> delegate;
//..
//Delegate for passing Mod and SubMod data back to VehicleSearchViewController
@property (strong) id delegate;
subvc.m
#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] setSearchFields:tempModArray IndexPath:tempModIndexPath];
//This pops to the View 1 - SearchViewController
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
然後在我的SearchViewController這是我如何設置代理的東西了
searchvc.h
#import "SubViewController.h"
@interface SearchViewController : UITableViewController <PassSubSearchData> {
//..
searchvc.m
- (void) setSearchFields:(NSArray *)modArray IndexPath:(NSIndexPath *)modIndexPath
{
modSearchObjectString = [[modArray valueForKey:@"MOD"] objectAtIndex:0];
modSearchIndexPath = modIndexPath; // Sets the selected IndexPath from the subview
NSLog(@"%@", modSearchObjectString);
NSLog(@"%@", modResultIndexPath);
[self.tableView reloadData];
}
這幾乎總結起來..對不起延遲。
你可以發佈代碼與問題的方法的聲明和調用該方法的代碼? – 2012-01-15 20:32:17
是的,現在就做。 – 2012-01-15 20:44:22
我有點不清楚你想做什麼。你真正需要的唯一的事情是將數據從表視圖傳遞到下一個視圖控制器,就像PopUp說的那樣? – 2012-01-15 21:02:01