Change from one view to another from a list with Objective C?

1

I have created a personalized list with code, I need that according to the selection so be the view that opens me, I do not know anything about this, I'm starting. I hope you can give me some help!

ViewController.h

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
@property (copy,nonatomic) NSArray *greekLetters;
@end

ViewController.m

#import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.greekLetters = @[@"Himnario",@"Informacion"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section{
return [self.greekLetters count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *SimpleIdentifier = @"SimpleIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleIdentifier];

if(cell == nil){
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleIdentifier];
}

UIImage *image1 = [UIImage imageNamed:@"himnario.png"];
UIImage *image2 = [UIImage imageNamed:@"informacion.png"];


cell.textLabel.text = self.greekLetters[indexPath.row];
//cell.textLabel.font = [UIFont boldSystemFontOfSize:10];
//ESTO ES EL TAMA;O DE LA FUENTE DE TEXTO

if (indexPath.row==0) {
    cell.detailTextLabel.text = @"Lista de himnos";
    cell.imageView.image= image1;
}
if (indexPath.row==1) {
    cell.detailTextLabel.text = @"Sobre el desarrollador";
    cell.imageView.image= image2;
}
return cell;
}

//ESTO SOLO ES PARA PROBAR CUANDO SELECCIONO ALGO DE ESTA LISTA
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *rowValue = self.greekLetters[indexPath.row];
NSString *message = [[NSString alloc] initWithFormat:@"Ha seleccionado: %@!",rowValue];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Item Seleccionado: " message:message delegate:nil cancelButtonTitle:@"Aceptar" otherButtonTitles:nil, nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];

}
//ESTO ES EL ANCHO DE LOS ITEMS
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}

@end
    
asked by Saúl Hernández 21.12.2017 в 07:53
source

1 answer

1

Assuming that in the Storyboard you have the segue configured with name, when you select a row, to add the view on top of the stack and that it is shown you must execute the following line of code:

[self performSegueWithIdentifier:@"nombreSegue" sender:self];

This will show the view as you have it configured in the viewcontroller, for example, push. You already have to take into account if it would be row 0, 1, ... n checking it with

if ([indexPath row] == 0)
{
    [self performSegueWithIdentifier:@"ventanaFila0" sender:self];
}

You also have a function to do what you need before the new view is shown, which would already be instantiated.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"nombreSegue"])
    {

    }
}
    
answered by 22.12.2017 / 12:34
source