0

我有应用程序,我有两个视图控制器,我的第一个视图和第二个视图控制器在 uipopovercontroller 中。我想要第二个视图控制器在第一个视图中的值,因为我已经创建了协议。这是我的代码。#import #import "SearchPopoverController.h" #import "AppDelegate.h"

@interface ViewController : UIViewController<PassSearchValueDelegate>{
AppDelegate *appDelegate;

SearchPopoverController *popSearch;

IBOutlet UILabel *lblAdd;
}

-(IBAction)showpop:(id)sender;
@end


#import "ViewController.h"

// my ViewController.m file code

-(void) getLocationList:(NSString *)strSearch{
lblAdd.text = strSearch;
}
-(IBAction)showpop:(id)sender{
if(![appDelegate.delObjSearchPopoverCon isPopoverVisible]){
    SearchPopoverController *popser = [[SearchPopoverController alloc] init];
    popSearch = popser;
    [popSearch setDelegate:self];

    appDelegate.delObjSearchPopoverCon = [[UIPopoverController alloc] initWithContentViewController:popSearch] ;

    [appDelegate.delObjSearchPopoverCon setPopoverContentSize:CGSizeMake(400 , 150)];
    [appDelegate.delObjSearchPopoverCon presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


}

}

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

@protocol PassSearchValueDelegate 
@required
-(void) getLocationList:(NSString *)strSearch;
@end
@interface SearchPopoverController : UIViewController <UITextFieldDelegate>{
AppDelegate *appDelegate;
IBOutlet UITextField *txtSearchAdd;
IBOutlet UILabel *lblSearchAdd;

id<PassSearchValueDelegate> _delegate;
}
@property (retain) id _delegate;
@end


//  my SearchPopoverController.m file code

-(IBAction)btnDoneSearch_clicked:(id)sender{

NSString *strAdd = [txtSearchAdd.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
strAdd = [strAdd stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[appDelegate.delObjSearchPopoverCon dismissPopoverAnimated:YES];

if (strAdd != nil || strAdd.length != 0) {
    [_delegate getLocationList:strAdd];
}
}

我在这条线上收到警告。

[popSearch setDelegate:self];

并且应用程序在下一行崩溃了。

请帮助我。任何帮助将不胜感激。

4

2 回答 2

0

重命名_delegatedelegate 你需要改变

@property (retain) id delegate;

@property (assign) id<PassSearchValueDelegate> delegate;

也在PassSearchValueDelegate.m添加

@implementation PassSearchValueDelegate //After this 
@synthesize delegate; //add this
于 2012-06-26T07:29:42.153 回答
0
id<PassSearchValueDelegate> _delegate;
// ...
@property (retain) id _delegate;

您的属性应该被命名delegate并且可能被合成以使用_delegate实例变量。您还应该在属性类型上指定协议。

此外,委托应该是assign(或weak在 ARC 下)属性。

于 2012-06-26T07:30:15.493 回答