iphone SDK - UITableView - не может назначить таблицу для представления таблицы - PullRequest
0 голосов
/ 08 октября 2009

это часть моего кода. Мое приложение падает, когда я пытаюсь загрузить представление, включая uitableview. Я думаю, что есть проблема с таблицей, которую я пытаюсь использовать, но не могу ее найти. помогите пожалуйста

    gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];

объявлено в .h как NSArray *gameTimingTable; это код, который я использую, чтобы назначить таблицу для uitableview

- (void)viewDidLoad {   

gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];



}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // There is only one section.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of time zone names.
    return [gameTimingTable count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";

    // Try to retrieve from the table view a now-unused cell with the given identifier.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    // If no cell is available, create a new one using the given identifier.
    if (cell == nil) {
        // Use the default cell style.
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    }

    // Set up the cell.
    NSString *cadence = [gameTimingTable objectAtIndex:indexPath.row];
    cell.textLabel.text = cadence;

    return cell;
}

/*
 To conform to Human Interface Guildelines, since selecting a row would have no effect (such as navigation), make sure that rows cannot be selected.
 */
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

спасибо большое

1 Ответ

0 голосов
/ 27 ноября 2009

Проблема здесь может быть одна (или обе) из двух вещей:

1 ... Вы возвращаете nil из метода willSelectRowAtIndexPath. Если вы не хотите, чтобы пользователь мог касаться ячеек, просто не переопределяйте этот метод, то есть вообще не трогайте его. Наряду с этим в методе cellForRowAtIndexPath вы можете сделать:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

, чтобы убедиться, что ячейка даже не выделяется, когда пользователь нажимает на нее.

2 ... То, как вы инициализировали массив gameTimingTable, означает, что он автоматически высвобождается после того, как вы его создали, поэтому к нему нельзя получить доступ в другом месте кода. Вместо этого инициализируйте его одним из следующих способов:

gameTimingTable=[[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil] retain];

// OR ...

 gameTimingTable=[[NSArray alloc] initWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];

... но не забудьте освободить массив в методе dealloc:

- (void)dealloc {
[gameTimingTable release];
[super dealloc];

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...