I have this problem with a tableview in iOS5 that is giving me errors, note that it works well with the older sdk.
This is the relevant code:
h file
#import
@interface WordListTableViewController : UITableViewController {
//NSMutableDictionary *words;
//NSArray *sections;
}
@end
m file
#import “WordListTableViewController.h”
#import “DefinitionViewController.h”
@interface WordListTableViewController()
@property (nonatomic, strong) NSMutableDictionary *words;
@property (nonatomic, strong) NSArray *sections;
@end
@implementation WordListTableViewController
@synthesize words, sections;
- (NSMutableDictionary *) words
{
if(!words){
NSURL *wordsURL = [NSURL URLWithString:@"http://localhost/Vocabulous.txt"];
words = [NSMutableDictionary dictionaryWithContentsOfURL:wordsURL] ;
}
return words;
}
- (NSArray *) sections
{
if(!sections)
{
sections = [[self.words allKeys] sortedArrayUsingSelector:@selector(compare:)] ;
}
return sections;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"WordListTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
//cell.textLabel.text = cell.textLabel.text = [self wordAtIndexPath:indexPath];
cell.textLabel.text = @"Test";
return cell;
}
h File for App Delegate
#import
@interface VocabAppDelegate : UIResponder <UIApplicationDelegate>
{
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *nav;
@end
m File for App Delegate with relevant code :
#import “VocabAppDelegate.h”
#import “WordListTableViewController.h”
@implementation VocabAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
WordListTableViewController *wltvc = [[WordListTableViewController alloc] init];
self.nav = [[UINavigationController alloc] initWithRootViewController: wltvc ];
self.window.rootViewController = self.nav;
[self.window makeKeyAndVisible];
return YES;
}
The Error is the following: EXEC_BAD_ACCESS
It’s like it only sets the visible cells and when I start scrolling down looking for the not visible ones, it’s like they can’t be displayed.
Fina UPDATE :
Following the advise from mattyhoe, I’ve replaced the method wordAtIndexPath with a static text, and followed the other two side notes Plus the way I use the delegate and it works !!!
Thanks
Nothing looks out of place there, so it’s likely the work you’re doing inside of wordAtIndexPath. To test this theory, simply replace that line with something like this:
As a side note, you do not need to declare ivars. Simply use
@propertys.Also, you likely want to set the accessory type when you’re allocing a new cell and not every time this method is called, so moving it inside the conditional makes sense.