У меня есть контроллер представления, который содержит табличное представление. Это табличное представление отображается в контроллере 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];
}