TableView в iOS 5 Сбой при включенной ARC - PullRequest
0 голосов
/ 06 ноября 2011

У меня есть эта проблема с таблицей в iOS5, которая выдает мне ошибки, обратите внимание, что она хорошо работает со старым sdk.Это соответствующий код: 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 Файл для делегата приложения #import

@interface VocabAppDelegate : UIResponder <UIApplicationDelegate>
{

}

@property (strong, nonatomic)  UIWindow *window;
@property (strong, nonatomic) UINavigationController *nav;
@end

m Файл для делегата приложения с соответствующим кодом: #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;

}

Ошибка следующая: EXEC_BAD_ACCESS Этокак будто он только устанавливает видимые ячейки, и когда я начинаю прокручивать вниз в поисках невидимых ячеек, они как будто не могут быть отображены.

Fina ОБНОВЛЕНИЕ: Следуя совету mattyhoe, я заменил методwordAtIndexPath со статическим текстом и последующими двумя примечаниями, а также способ использования делегата, и он работает !!!

Спасибо

1 Ответ

0 голосов
/ 06 ноября 2011

Ничто не выглядит неуместно, так что, скорее всего, работа, которую вы выполняете внутри wordAtIndexPath. Чтобы проверить эту теорию, просто замените эту строку на что-то вроде этого:

cell.textLabel.text = @"Hello";

В качестве примечания вам не нужно объявлять ивара. Просто используйте @property s. Кроме того, вы, вероятно, захотите установить тип аксессуара при выделении новой ячейки, а не при каждом вызове этого метода, поэтому имеет смысл перемещать его внутри условного выражения.

...