iPhone编码:选择UITableView时出现问题 [英] iPhone Coding: Problem with UITableView selection
问题描述
我的UITableView有一个奇怪的问题.我希望表中的所有单元格都是可选择的,这样,如果选择了一个单元格,则将执行适当的操作.除了第0行的单元格(该单元格出现在表的顶部)之外,当前表格中的所有单元格都是可选的.即使已将其设置为允许选择,该单元也不是可选的.有任何想法吗?
I have a strange problem with my UITableView. I want all the cells in the table to be selectable, such that if a cell is selected, an appropriate action is executed. All the cells in my table are currently selectable apart from the cell at row 0 (the cell at that appears at the top of the table). This cell is not selectable, even though it has been set to allow for selection. Any ideas?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
tableView.allowsSelection = YES;
static NSString *SettingsTableID = @"SettingsTableID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingsTableID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier: SettingsTableID] autorelease];
}
cell.textLabel.text = [tableHeadingsArray objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
非常感谢.
推荐答案
对不起,大家好,我很傻.:)这段代码在我的ViewController子类中.我从一个示例中复制了该类,却忘记在使用它之前进行了彻底的检查.
Sorry everyone, I'm being stupid. :) This code was in my ViewController sub-class. I copied the class from an example, and forgot to check it over thoroughly before using it.
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
if (row == 0)
return nil;
return indexPath;
}
删除此问题已解决问题.
Deleting this has fixed the problem.
干杯.
这篇关于iPhone编码:选择UITableView时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!