當我點擊一個UIPopoverController
單元時,我需要打開一個ViewController
。 SeccionesViewController
是ViewController
,我在UIPopoverController
,這是一個表。不起作用的功能是TableView
的didSelectRowAtIndexPath
。當我點擊UIPopoverController中的一個單元時推送一個新的UIViewController
謝謝您的提前。
我的代碼顯示UIPopoverController
是:
-(IBAction)seccionesButtonTapped:(id)sender
{
if (_itemPicker == nil) {
//Create the ColorPickerViewController.
_itemPicker = [[SeccionesViewController alloc] initWithStyle:UITableViewStylePlain];
//Set this VC as the delegate.
_itemPicker.delegate = self;
}
if (_itemPickerPopover == nil) {
//The color picker popover is not showing. Show it.
_itemPickerPopover = [[UIPopoverController alloc] initWithContentViewController:_itemPicker];
//[_itemPickerPopover presentPopoverFromBarButtonItem:(UIBarButtonItem *) sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[_itemPickerPopover presentPopoverFromRect:CGRectMake(350, 902, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else {
//The color picker popover is showing. Hide it.
[_itemPickerPopover dismissPopoverAnimated:YES];
}
}
的SeccionesViewController
代碼:
-(id)initWithStyle:(UITableViewStyle)style
{
if ([super initWithStyle:style] != nil) {
//Initialize the array
_itemNames = [NSMutableArray array];
//Set up the array of colors.
[_itemNames addObject:AMLocalizedString(@"listaTareas", @"")];
[_itemNames addObject:AMLocalizedString(@"EventosTab", @"")];
//Make row selections persist.
self.clearsSelectionOnViewWillAppear = NO;
//Calculate how tall the view should be by multiplying the individual row height
//by the total number of rows.
NSInteger rowsCount = [_itemNames count];
NSInteger singleRowHeight = [self.tableView.delegate tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSInteger totalRowsHeight = rowsCount * singleRowHeight;
//Calculate how wide the view should be by finding how wide each string is expected to be
CGFloat largestLabelWidth = 0;
for (NSString *itemName in _itemNames) {
//Checks size of text using the default font for UITableViewCell's textLabel.
CGSize labelSize = [itemName sizeWithFont:[UIFont boldSystemFontOfSize:20.0f]];
if (labelSize.width > largestLabelWidth) {
largestLabelWidth = labelSize.width;
}
}
//Add a little padding to the width
CGFloat popoverWidth = largestLabelWidth + 100;
//Set the property to tell the popover container how big this view will be.
self.contentSizeForViewInPopover = CGSizeMake(popoverWidth, totalRowsHeight);
}
return self;
}
#pragma mark - View Lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_itemNames count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [_itemNames objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedItem = [_itemNames objectAtIndex:indexPath.row];
NSUserDefaults *dispositivo = [NSUserDefaults standardUserDefaults];
NSString *dis = [dispositivo stringForKey:@"dispositivo"];
if ([selectedItem isEqualToString:AMLocalizedString(@"listaTareas", @"")]) {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:dis bundle:nil];
ListaTareasViewController *tareas= [storyBoard instantiateViewControllerWithIdentifier:@"ListaTareasView"];
tareas.communitykey = communitykey;
tareas.tituloAsig = tituloAsig;
tareas.infoH = infoH;
if ((vengoDe != 1) && (vengoDe != 2) && (vengoDe != 3)) {
tareas.vengoDe = 1;
}else{
tareas.vengoDe = vengoDe;
}
tareas.infoAsig = infoAsig;
[self.navigationController pushViewController:tareas animated:YES];
}else if ([selectedItem isEqualToString:AMLocalizedString(@"EventosTab", @"")]){
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:dis bundle:nil];
ListaEventosViewController *eventos= [storyBoard instantiateViewControllerWithIdentifier:@"listaEventosView"];
eventos.communitykey = communitykey;
eventos.nomAsig = tituloAsig;
eventos.infoH = infoH;
if ((vengoDe != 1) && (vengoDe != 2) && (vengoDe != 3)) {
eventos.vengoDe = 1;
}else{
eventos.vengoDe = vengoDe;
}
eventos.infoAsig = infoAsig;
[self.navigationController pushViewController:eventos animated:YES];
}
}
就像這樣:'self.navigationController.delegate = self;'?? – amurcia
對不起,但我很迷茫... – amurcia
不,傳回給委託就像'[self.delegate seccionesViewController:self didSelectItem:## XXX ##];'其中## XXX ##是視圖控制器或選定的項目。 – Wain