Actualmente estoy escribiendo mi primera aplicación para iPhone, pero he tenido un problema. Tengo una vista que contiene una UITableView. Esta es la primera vez que intento esto, y este es el comportamiento que intento lograr:Llamar a una nueva vista al seleccionar una fila en un 'UITableView'
Cuando el usuario selecciona una de las filas, me gustaría que llamara a una nueva vista, llevando al usuario a una página diferente que muestra información en referencia a lo que han seleccionado.
Lo tengo actualmente, así que cuando el usuario selecciona una fila, muestra un UIAlert en la misma vista, pero esto no satisface mis necesidades. Configuré UITableView a través del constructor de la interfaz e ingresé el siguiente código en mi archivo .m para configurarlo.
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
//return the value
return 10;
}
//now we define the cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Identifier for retrieving reusable cells.
static NSString *cellIdentifier = @"MyCellIdentifier";
// Attempt to request the reusable cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// No cell available - create one
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
// Set the text of the cell to the row index.
cell.textLabel.text = [NSString stringWithFormat:@"iPad %d", indexPath.row];
return cell;
}
Esto crea una lista de diez filas. Los siguientes códigos me dan mi UIAlert cuando se toca, sin embargo, quiero eliminar esto y hacer que llame a una nueva vista de mi elección;
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Show an alert with the index selected.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"iPad Selected"
message:[NSString stringWithFormat:@"iPad %d", indexPath.row]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
¿Alguien puede ayudar con este último fragmento de código? la vista que quiero que llame se llama 'ProteinView'.
Esta es una respuesta correcta, pero (a) presume que OP usa un controlador de vista de navegación, y (b) realmente no explica las diferentes partes involucradas: nuevos controles de vista, XIB y el 'título 'atributo. Tal vez elaborar un poco? – Tim
He usado ese ejemplo, compilado, etc., la UIToolBar muestra bien. pero cuando se toca una fila, la aplicación falla. #Dismayed! –
Parece dar una advertencia basada en ese [NSString withFormat: pieza de código. Vea la captura de pantalla si alguien todavía está leyendo esto :-) - http://d.pr/AKNb –