2012-01-15 23 views
1

我正在此錯誤無法識別的選擇器,委派問題

[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]; 
} 

這幾乎總結起來..對不起延遲。

+0

你可以發佈代碼與問題的方法的聲明和調用該方法的代碼? – 2012-01-15 20:32:17

+0

是的,現在就做。 – 2012-01-15 20:44:22

+0

我有點不清楚你想做什麼。你真正需要的唯一的事情是將數據從表視圖傳遞到下一個視圖控制器,就像PopUp說的那樣? – 2012-01-15 21:02:01

回答

1

因此,從我所知道的情況來看,將信息存儲到文件中,然後在需要時將其還原,可能是實現您想要的更簡單的方法。事(我知道,過於簡單化)是這樣的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    //store the cell's title into a string 
    NSString* string = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text]; 

    [[NSUserDefaults standardUserDefaults] setObject:string forKey:@"someKey"]; 
} 

以後可以得到該字符串後面使用:

NSString* titleString = [[NSUserDefaults standardUserDefaults] objectForKey:@"someKey"]; 

您可以用你需要傳遞的信息同樣的方式進行。

另一種方法是創建視圖控制器屬性接收數據:

@property(nonatomic, retain) NSString* string; //you need to synthesize it in the .m file too 

那麼你彈到你做的視圖控制器前:

//make sure you cast it 
(SearchViewController*)[self.navigationController.viewControllers objectAtIndex:1].string = @"some string"; 

然後,一旦你去那個控制器,該屬性將設置任何字符串,您將其設置爲在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

並以這些方式可以在視圖控制器之間傳遞信息。祝你好運!

+0

好吧很酷的傢伙感謝您的幫助我要給這個嘗試一些研究,看看我如何繼續。謝謝回覆。 – 2012-01-15 21:45:46

相關問題