iOS UITableview Crashing??

yaboy10holla

macrumors newbie
Original poster
Feb 19, 2011
17
0
hi guys,

i added a table to my interface builder interface, linked it up with a controller by connecting the datasource outlet and view reference to that controller, and populated it with an array defined in the controller implementation file (do i have to attach the delegate too?).

Whenever I test it out on the simulator, the application crashes whenever a cell that has moved off screen needs to come back on screen. So scrolling causes the app to crash. I was thinking maybe there is a problem with the dequeueResuableCellWithIdentifier method, but I didnt alter it at all so I don't know why this would be the case for such a simple task. Any help is greatly appreciated.
 

yaboy10holla

macrumors newbie
Original poster
Feb 19, 2011
17
0
Sure here is my code from the table controller:

Code:
#import "OneTableController.h"
#import "PracticeAppDelegate.h"
#import "OneViewController.h"


@implementation OneTableController

@synthesize wallPostArray;

/*
- (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 {
	
	NSMutableArray *myarray = [[NSMutableArray alloc]initWithObjects:
							   @"Item One",@"Item Two",nil];
	self.wallPostArray = myarray;
	[myarray release];
    [super viewDidLoad];

    // 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 [self.wallPostArray count];
}


// Customize the appearance of table view cells.
- (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] autorelease];
    }
    
    // Set up the cell...
	NSUInteger row = [indexPath row];
	[[cell textLabel]setText:[wallPostArray objectAtIndex:row]];
	
    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 {
	[wallPostArray release];
    [super dealloc];
}


@end
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
Well what is the wallPostArray thing.

And this [[cell textLabel]setText:[wallPostArray objectAtIndex:row]];
Could be just like this
Code:
cell.textLabel.text = [wallPostArray objectAtIndex:indexpath.row];
just try this in ur .H file.

Code:
NSArray *testArray;

@property (nonatomic, retain) NSArray *testArray.
in ur .M file.

Code:
viewDidLoad -->
testArray = [[NSArray alloc] initWithContents:@"test1", @"Test 2", nil];

then the step above, which i showed u
cell.textLabel.text = [testArray objectAtIndex:indexPath.row];
also for the count go like this

Code:
 return [testArray count];
And yes u need the delegate. but double check ur .H file
so it does actually implement the delegate :)
Also, if u point ur view to it, don't u have a view box where it's in, or the view is purely the tableview.
Without all that info, we can't help u .