UIPopoverController
셀을 클릭하면 ViewController
을 열어야합니다. SeccionesViewController
은 내가 UIPopoverController
에 넣은 ViewController
입니다. 이것이 테이블입니다. 작동하지 않는 기능은 didSelectRowAtIndexPath
에서 TableView
입니다.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
코드는 다음과 같습니다
//Set this VC as the delegate.
_itemPicker.delegate = self;
당신이있어 것처럼 보이게 :
-(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