iphone sdk-UITableView-无法将表分配给表视图
这是我代码的一部分。当我尝试加载包含uitableview的视图时,我的应用程序崩溃。 我想我想用的桌子有问题,但找不到。 请帮忙iphone sdk-UITableView-无法将表分配给表视图,iphone,uitableview,nsarray,Iphone,Uitableview,Nsarray,这是我代码的一部分。当我尝试加载包含uitableview的视图时,我的应用程序崩溃。 我想我想用的桌子有问题,但找不到。 请帮忙 gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil]; 在.h中声明为NSArray*游戏计时表; 这是我用来将表分配给uitableview的代码 - (void)viewDidLoad { gameTim
gameTimingTable=[NSArray arrayWithObjects:@"2min + 10sec/coup",@"1min + 15sec/coup",@"5min",nil];
在.h中声明为NSArray*游戏计时表;
这是我用来将表分配给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…您正在从willSelectRowAtIndexPath方法返回nil。如果您不希望用户能够点击单元格,请不要覆盖此方法,即根本不要触摸它。此外,在CellForRowatineXpath方法中,您可以执行以下操作:
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];
}有什么想法吗。。。。。。。。。。。。。。。。。。。。。。。塔克斯