0

これは私のコードの一部です。uitableview を含むビューを読み込もうとすると、アプリケーションがクラッシュします。使用しようとしているテーブルに問題があると思いますが、見つかりません。助けてください

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

NSArray *gameTimingTable; これは、テーブルをuitableviewに割り当てるために使用しているコードであるため、.hで宣言されています

- (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;
}

どうもありがとう

4

1 に答える 1

0

ここでの問題は、次の 2 つのいずれか (または両方) である可能性があります。

1... willSelectRowAtIndexPath メソッドから nil を返しています。ユーザーがセルをタップできないようにする場合は、このメソッドをオーバーライドしないでください。つまり、まったく触れないでください。それに加えて、 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];

}

于 2009-11-27T17:37:55.133 に答える