我有一个包含 tableview 的视图控制器。这个 tableview 显示在父视图的 UIPopover 控制器中。我希望弹出控制器中选定单元格的文本设置在父视图的 UITextField 中,我想关闭选择后的弹出窗口。我无法做到这一点。
弹出框控制器的代码
.h 文件
#import <UIKit/UIKit.h>
@protocol SelectLocationViewControllerDelegate <NSObject>
- (void)locationSelected:(NSString *)location;
@end
@interface SelectLocationViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
IBOutlet UITableView *locationTableView;
NSArray *locationtypes;
id delegate;
}
@property (nonatomic, retain) UITableView * locationTableView;
@property (nonatomic, retain) NSArray * locationtypes;
@property (nonatomic, assign) id<SelectLocationViewControllerDelegate> delegate;
@end
弹出框的 .m 文件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
NSString *locationSelected = [self.dwellingTypes objectAtIndex:row];
[self.delegate locationSelected: locationSelected]; // This don't gets invoked.
}
家长班
- (void) locationSelected:(NSString *)location {
----Here i set the the text for text field and dismiss the popover----
[popoverController dismissPopoverAnimated:YES];
}
父类中存在的 locationselected 方法不会被调用。
请任何机构帮助我摆脱这个问题。
谢谢你
我正在创建的弹出框是否正确?
.h file
#import <UIKit/UIKit.h>
#import "SelectLocationViewController.h"
@interface SearchViewController : UIViewController<SelectLocationViewControllerDelegate,UIPopoverControllerDelegate>{
SelectLocationViewController * selectLocationViewController;
UIPopoverController * locationpopover;
IBOutlet UITextField *locationSelectedField;
}
@property (nonatomic, retain) UIPopoverController * locationpopover;
@property (nonatomic, retain) SelectLocationViewController * selectLocationViewController;
.m file
- (void)viewDidLoad {
selectLocationViewController=[[SelectLocationViewController alloc]init]; //The class which i am displaying inside the popover
selectLocationViewController.delegate=self;
UINavigationController *navigationcontroller=[[UINavigationController alloc]initWithRootViewController: selectLocationViewController];
locationpopover = [[UIPopoverController alloc] initWithContentViewController:navigationcontroller];
[locationpopover setPopoverContentSize:CGSizeMake(290,410) animated:YES];
[locationpopover setDelegate:self];
}
- (void)itemSelected:(NSString *)dwelling //This is the method which is called from the other class when a row is selected from the tableview in SelectLocationViewController class
{
locationSelectedField.text= dwelling;
NSLog(@"DwellingSelectedField iside tap:%@",dwelling); //I get the text printed here
[locationpopover dismissPopoverAnimated:YES];
}