デリゲートを使用して、ナビゲーションスタック上のサブビューと親ビューの間にいくつかの情報を渡そうとしています。デリゲートが正しく動作しません
私はサブビューからデリゲートを実行するとき何らかの理由で、親ビューで設定されたデリゲートメソッドを入力しないで、ナビゲーションコントローラからサブビューをポップします..私はNSLogsを試しました&スレッドがブレークポイントです私はあなたが私を助けてくれることを望んでいたので、主な視点でこの代理人の方法に挑戦していません。
まず最初に、私が私のサブウィンドウと呼んでいるところで私の代議員をどのように設定したのかを見せて、メインビューで設定したところで、あなたは私がこれまでにないもの。
Subview.hは//私は、デリゲートとは関係のない物事を残している
#import <UIKit/UIKit.h>
//Delegate - Protocol stuff for passing data from this view to the parent view
@protocol PassSearchData <NSObject>
@required
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath;
@end
@interface SecondViewController : UITableViewController <UITableViewDataSource> {
//Delegate (Used to pass information back to parent view)
id <PassSearchData> delegate;
}
//Delegate (Used to pass information back to parent view)
@property (strong) id delegate;
@end
SecondView.m
#import "SecondViewController.h"
#import "FirstViewController.h"
@implementation SecondViewController
//..
//Delegate (Used to pass information back to parent view)
@synthesize delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Access selected cells content (cell.textLabel.text)
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Parent view logic (sends info back to the correct cell in parent view)
if (parentViewSelectedIndexPath.section == 0)
{
if (parentViewSelectedIndexPath.row == 0)
{
//Predicates restrict the values that will be returned from the query
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"MANUFACTURER",cell.textLabel.text];
filterArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate];
[[self delegate]setManufactureSearchFields:filterArray withIndexPath:indexPath];
// NSLog(@"Filtered Array = %@", filterArray);
}
}
[self.navigationController popViewControllerAnimated:YES]; //pops current view from the navigatoin stack
}//...
その後、これは私がFirstViewController
の内側にそれを設定する方法でありますFirstViewController.h
#import <UIKit/UIKit.h>
#import "VehicleResultViewController.h" //With this included I can now use the PassSearchData delegates of this view for passing data
@interface VehicleSearchViewController : UITableViewController <PassSearchData> {
//..
FirstViewController.m
#import "VehicleSearchViewController.h"
#import "VehicleResultViewController.h" //Subview
//..
#pragma mark - Received data from Sub view delegates
//These are the delegate method for passing data from the child to the parent view (parent being this view, with the delegate being declared in the subview)
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = [[arrayValues valueForKey:@"MANUFACTURER"] objectAtIndex:0];
manufactureIdString = [[arrayValues valueForKey:@"MANUFACTURERID"] objectAtIndex:0]; //Restricts Models dataset
manufactureResultIndexPath = myIndexPath;
}
誰もが私が欠けていることを知っている場合は/任意のヘルプはどんな質問が私に教えて
本当にheapfulだろう間違っています。
firstviewcontrollerでソリューション
私は のtableView内secondviewcontrollerをロードするために行く:didSelectRowAtIndexPath:私は、ナビゲーションスタックにビューをプッシュする前に、私は.. secondviewcontrollersデリゲートを設定するのを忘れたので、不足しているコードはでしたこの。
FirstView.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the subview ready for use
VehicleResultViewController *vehicleResultViewController = [[VehicleResultViewController alloc] initWithNibName:@"VehicleResultViewController" bundle:nil];
//Pass the selected object to the new view controller.
[self.navigationController pushViewController:vehicleResultViewController animated:YES];
[vehicleResultViewController setDelegate:self];
//etc
みんなありがとう。
すなわち
大丈夫私は弱いに私の参照を変更したが、今、私はこの奇妙なエラーを取得しています。 ** _weakプロパティ 'delegate'の既存のivar 'delegate'は_weakでなければなりません**また、私は、SecondViewControllerがインスタンス化され、デリゲートがどこにあるのかをあなたに教えてくれる場所を100%確信していません。 set ..私はfirstviewcontrollerからナビゲーションスタックにsecondviewcontrollerをロードするときを指していますか? –
thatsまさにあなたが参照していたものです。私は、上に追加された解決策を使って問題を解決しました。大いに助けを借りて...完全に自分自身を笑ってしまいました。 –
あなたはそれを解決してうれしいです。 _weak ivarのリファレンスも解決しましたか?あなたはivar宣言を削除し、コンパイラがそれを生成できるようにするかもしれません。また、プロパティ宣言に after idを追加する必要があります。 –
Jerry