2011-03-13 40 views
0

底线:我希望我的表格中的所有行/单元格在第一次查看时显示重新排序图标。第一个UITableView单元格/行不会显示重新排序图标

背景:在初始查看表格时,表格中的第0行(第一个单元格)不会显示重新排序图标,但后续单元格会显示它。我正在使用UITableViewCell构建我的表。 NSLog显示(见下文)编辑(允许重排序图标出现)最初没有对第0行启用,但是对于以后的行。将第0行滚动到视图之外后,返回到视图编辑处于启用状态,从而允许我查看重新排序图标(请参阅下面的NSLog)。我认为这可能是一个重用问题,但是我在所有行中都包含UILabels,以包含第0行,显示正常。我认为这是一个简单的解决方法,但只是无法弄清楚。任何帮助将不胜感激!

2011-03-13 12:48:57.750 VBSTAT [4305:207]行:0编辑:0 indexPath:81108000

2011-03-13 12:48:57.751 VBSTAT [4305:207]行:1编辑:1个indexPath:81108144

2011-03-13 12:48:57.752 VBSTAT [4305:207]行:2编辑:1个indexPath:81108224

2011-03-13 12点48: 57.753 VBStat [4305:207] row:3 editing:1 indexPath:81108304

2011-03-13 12:48:57.753 VBStat [4305:207] row:4 editing:1 indexPath:8110 8384

2011-03-13 12:48:57.754 VBSTAT [4305:207]行:5编辑:1个indexPath:81108464

2011-03-13 12:49:32.469 VBSTAT [4305:207]行:0编辑:1个indexPath:81108000

-(UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellTableIdentifier = @"CellTableIdentifier "; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellTableIdentifier]; 

NSUInteger row = [indexPath row]; 
NSDictionary *rowData = [self.list objectAtIndex:row]; 





    //stuff for labels... 
     UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag]; 
     name.text = [rowData objectForKey:@"Name"]; 
     UILabel *color = (UILabel *)[cell.contentView viewWithTag:kColorValueTag]; 
     color.text = [rowData objectForKey:@"Color"]; 

if (cell == nil) { 
{ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellTableIdentifier] autorelease]; 

    NSLog(@"row: %i editing: %d indexPath: %d rowData %d", row, tableView.editing, indexPath, rowData); 

    ...Labels generated here... 
} 

tableView.editing = YES; 
cell.showsReorderControl=YES; 

} 
+0

通过将tableView.editing移出if语句来修复0行编辑问题。现在在NSLog中显示0行编辑1,但它仍然不显示重新排序图标... uggg ... – groovedpavement

+0

更多信息...做了另一个NSLog并观察了Debugger Console中的操作。注意到对于所有单元格,在初始视图中将showsReorderContol设置为0,我假设它并未设置,即使除第一个单元格(第0行)以外的所有单元格都出现重新排序控件。滚动发生后,对于所有行,重排序被设置为1,此时第0行的重排序控件出现。我现在假设我必须在其他地方插入cell.showReorderingControl,以便在表第一次出现时设置它,但是我在哪里插入它? – groovedpavement

回答

0

你实现方法

  • (BOOL)的tableView:(UITableView的*)的tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 返回YES; }

  • (无效)的tableView:(UITableView的*)的tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {

}

和......你需要后

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellTableIdentifier]; 

if (cell == nil) { 
{ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellTableIdentifier] autorelease]; 

    NSLog(@"row: %i editing: %d indexPath: %d rowData %d", row, tableView.editing, indexPath, rowData); 

    ...Labels generated here... 
} 

,因为你使用(*的UILabel)的第一行中移动这件事[cell.contentView当细胞根本不存在

+0

是的,我确实实施了这两种方法。关于,(UILabel *)...我评论了与UILabels有关的所有事情,看看它是否改变了任何事情,事实并非如此。顺便说一句,不要为我所做的事情感到骄傲(因为我想找出导致我的问题),但我确实做了一些工作。由于我需要的视图发生在滚动后,我在第一个视图(使用scrollRectToVisible和scrollToRowAtIndexPath)时实现了自动滚动。我怀疑苹果希望你从一个工具栏按钮这样的动作来实现重新排序控制,而不是像我正在尝试的那样在第一个视图上自动加载。谢谢! – groovedpavement

相关问题