I'm new to this forum and to SDK programming and I'm trying to achieve this as a test application. I have a window-based application with two views and a navigation bar. The first view has a button which pushes the view on a tableview, The tableview loads the data from an array whose elements fill one label for each cell. The cells also have another label and a button. The "big" label loads the data correctly, as well as the second ("small") label shows correctly the given text. The problems begin with the buttons. The buttons should change the text of the "big" label into something else I declared within a method in the cell definition class but instead, although it compiles and runs, the applciation doesn't fill the buttons with the given text and crashes when I click any ofthe buttons. I followed the code of another user to do this but doesn't seem to work with me. I'll post here all the files I've done for this:
//
// ListaRicette.m
#import "CustomCell.h"
#import "ListaRicette.h"
@implementation ListaRicette
@synthesize lista;
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:style]) {
}
return self;
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Le ricette sfiziose";
lista = [[NSMutableArray alloc] initWithObjects:@"Polenta",@"Salciccie",@"Piselli",@"Cotechino",@"Ravioli",@"Pancetta",nil];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
/*
- (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 any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return[lista count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"%@%d",@"CellID_", indexPath.row];
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.bigLabel.text =[lista objectAtIndex:indexPath.row];
//[cell setTag:[indexPath row]];
cell.smallLabel.text = @"Testo piccolo x tutti";
[cell.button setTitle:@"LOL" forState:UIControlStateNormal];
[cell.button addTarget:self action:@selector(UpdateLabel:) forControlEvents:UIControlEventTouchUpInside];
return cell;
/*UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
if (cell == nil){
cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:@"cellID"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text =[lista objectAtIndex:indexPath.row];
cell.detailTextLabel.text =[lista objectAtIndex:indexPath.row];//@"LOL";
return cell;*/
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [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 editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// 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
I tried to search the forum for a solution but nothing seemed to help. This is really driving me crazy so any kind of help will be appreciated. Sorry for my awful english and thanks in advance.