Vai al contenuto

Popup diverso a seconda della riga


Messaggi raccomandati

Ciao, ho una tabella con diverse righe, quando clicchi su una rifga esce un popup ma nel popup mi appare scritto il contenuto della riga, io invece vorrei un popup con scritto quello che dico io in ogni riga.

Come faccio

Siediti lungo la riva del fiume e aspetta, prima o poi vedrai passare il cadavere del tuo nemico.

Link al commento
Condividi su altri siti

dovresti creare un messaggio diverso in base alla riga.

nel metodo didSelectRowAtIndexPath potresti inserire una cosa del genere:

	NSString *message;
switch (indexPath.row) {
	case 0:
		message = @"Ciao";
		break;

	case 1:
		message = @"Salve";
		break;

	case 2:
		message = @"Arrivederci";
		break;
}

UIAlertView *alert = [[uIAlertView alloc] initWithTitle:@"Titolo" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

Hai un'idea per un'app ma non sai programmare? Contattami. Trovi gli indirizzi sul mio sito: http://www.2ciphonedevelopers.com

Link al commento
Condividi su altri siti

Guarda ti posto il codice del programma.

//
//  RootViewController.m
//  myTable
//
//  Created by  on 24/03/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "TabellaController2.h"

@implementation TabellaController2

@synthesize lista, filteredListContent;

- (void)viewDidLoad {
   [super viewDidLoad];

self.title = @"UNIX (Mac & Linux)";

//elementi da visualizzare nella tabella 
lista = [[NSMutableArray alloc] initWithObjects:@"Azione 1", @"Azione 2", 
		 @"Azione 3", @"Azione 4", @"Azione 5", @"Azione 6", @"Azione 7", @"Azione 8", 
		 @"Azione 9", nil];	

// crea la lista filtrata, inizializzandola con il numero di elementi dell'array "lista"
filteredListContent = [[NSMutableArray alloc] initWithCapacity: [lista count]];
//inserisce in questa  nuova lista gli elementi della lista originale 
[filteredListContent addObjectsFromArray: lista];
}


/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
   [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release anything that can be recreated in viewDidLoad or on demand.
// e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
   return 1;
}


//setta il numero di righe della tabella
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//il numero di righe deve corrispondere al numero di elementi della lista
return [filteredListContent count];
}


// Setta il contenuto delle varie celle 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"]; 

if (cell == nil){ 
	cell = [[[uITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellID"] autorelease]; 
	//setta lo stile con cui vengono selezionate le righe 	 
} 
//inseriamo nella cella l'elemento della lista corrispondente 
cell.textLabel.text = [filteredListContent objectAtIndex:indexPath.row];
return cell; 
} 


// Se selezioniamo una riga appare un pop-up con l'elemento in questione
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *popUp = [[uIAlertView alloc] initWithTitle:@"Hai selezionato:" message:[filteredListContent objectAtIndex:indexPath.row] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[popUp show];
[popUp release];
}


- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope{

// per prima cosa azzeriamo l'array della ricerca
[self.filteredListContent removeAllObjects]; 

// controlliamo se gli elementi della tabella corrispondono alla ricerca
NSString *cellTitle;
for (cellTitle in lista){
	NSComparisonResult result = [cellTitle compare:searchText options:NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])];
	if (result == NSOrderedSame){
		[filteredListContent addObject:cellTitle];
	}
}
}

#pragma mark -
#pragma mark UISearchDisplayController Delegate Methods

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
   [self filterContentForSearchText:searchString scope:
 [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

   // Return YES to cause the search result table view to be reloaded.
   return YES;
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption{

   [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
 [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

   // Return YES to cause the search result table view to be reloaded.
   return YES;
}

/*
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Navigation logic may go here -- for example, create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController animated:YES];
// [anotherViewController release];
}
*/


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/


- (void)dealloc {
   [super dealloc];
}


@end

Il pezzo dove sta scritto "// Se selezioniamo una riga appare un pop-up con l'elemento in questione" è quello che devo modificare. Io non sono molto esperto lo faccio a tempo libero, se potevi dirmi esattamente come inserire quello che mi hai detto prima per far apparire una cosa diversa ogni volta.

Grazie

Siediti lungo la riva del fiume e aspetta, prima o poi vedrai passare il cadavere del tuo nemico.

Link al commento
Condividi su altri siti

  • 2 settimane dopo...

Archiviato

Questa discussione è archiviata e chiusa a future risposte.

×
×
  • Crea Nuovo...