使用协议应用程序崩溃ipad

时间:2012-06-26 07:25:34

标签: ios ipad protocols uipopovercontroller

我有应用程序,我有两个视图控制器我的第一个视图和第二个视图控制器在uipopovercontroller。我希望第一个视图中的第二个视图控制器的值为我创建的协议。这是我的代码。     #进口     #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];

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

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

2 个答案:

答案 0 :(得分:0)

_delegate重命名为delegate 您需要更改

@property (retain) id delegate;

@property (assign) id<PassSearchValueDelegate> delegate;

同样在PassSearchValueDelegate.m添加

@implementation PassSearchValueDelegate //After this 
@synthesize delegate; //add this

答案 1 :(得分:0)

id<PassSearchValueDelegate> _delegate;
// ...
@property (retain) id _delegate;

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

此外,代表应该是assign(或ARC下的weak)属性。