<i id='VdUb2'><tr id='VdUb2'><dt id='VdUb2'><q id='VdUb2'><span id='VdUb2'><b id='VdUb2'><form id='VdUb2'><ins id='VdUb2'></ins><ul id='VdUb2'></ul><sub id='VdUb2'></sub></form><legend id='VdUb2'></legend><bdo id='VdUb2'><pre id='VdUb2'><center id='VdUb2'></center></pre></bdo></b><th id='VdUb2'></th></span></q></dt></tr></i><div id='VdUb2'><tfoot id='VdUb2'></tfoot><dl id='VdUb2'><fieldset id='VdUb2'></fieldset></dl></div>

  1. <small id='VdUb2'></small><noframes id='VdUb2'>

    1. <tfoot id='VdUb2'></tfoot>

        <bdo id='VdUb2'></bdo><ul id='VdUb2'></ul>
      <legend id='VdUb2'><style id='VdUb2'><dir id='VdUb2'><q id='VdUb2'></q></dir></style></legend>
    2. UITableView中默认重新加载后如何记住选择的行并维护它们?

      How to remember rows selected and maintain them after reload by default in UITableView?(UITableView中默认重新加载后如何记住选择的行并维护它们?)

        <tbody id='wAlZX'></tbody>

    3. <i id='wAlZX'><tr id='wAlZX'><dt id='wAlZX'><q id='wAlZX'><span id='wAlZX'><b id='wAlZX'><form id='wAlZX'><ins id='wAlZX'></ins><ul id='wAlZX'></ul><sub id='wAlZX'></sub></form><legend id='wAlZX'></legend><bdo id='wAlZX'><pre id='wAlZX'><center id='wAlZX'></center></pre></bdo></b><th id='wAlZX'></th></span></q></dt></tr></i><div id='wAlZX'><tfoot id='wAlZX'></tfoot><dl id='wAlZX'><fieldset id='wAlZX'></fieldset></dl></div>

      <small id='wAlZX'></small><noframes id='wAlZX'>

      <tfoot id='wAlZX'></tfoot>

          1. <legend id='wAlZX'><style id='wAlZX'><dir id='wAlZX'><q id='wAlZX'></q></dir></style></legend>
              <bdo id='wAlZX'></bdo><ul id='wAlZX'></ul>
                本文介绍了UITableView中默认重新加载后如何记住选择的行并维护它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何设置默认选中的行?我想选择一行,使用 indexpath.row 获取所选行的数量,然后重新加载表格并选择所选行.有人能帮助我吗?我可以在方法 -(IBAction) segmentedControlIndexChanged 中获取选定的行吗?不在 didSelectRowAtIndexPath 中?

                How can I set a row selected by default? I want to select a row , take the number of selected row with indexpath.row and then reload the table and select the row what was selected. Can someone help me please? Can I get the selected row in a method -(IBAction) segmentedControlIndexChanged? Not in didSelectRowAtIndexPath?

                这是我的代码,如果它可以帮助你理解

                This is my code if it can help you to understand

                - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
                {
                    static NSString *CellIdentifier = @"Cell";
                
                    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                    if (cell == nil) {
                        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                    }
                    //lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(200, 10, 100, 20) ];
                
                    // Configure the cell...
                    NSString *depdateChoosed=[deparatureDates objectAtIndex:depSelectedIndice];
                    NSString *comeateChoosed=[deparatureDates objectAtIndex:comSelectedIndice];
                    NSString *choosedDate =[NSString stringWithFormat:@"%@%@",depdateChoosed, comeateChoosed];
                    NSLog(@"date choisi %@ ",choosedDate);
                
                    if(segment.selectedSegmentIndex==0)
                    {
                        cell.textLabel.text =[deparatureDates objectAtIndex:indexPath.row];        
                    }
                    else if(segment.selectedSegmentIndex==1) {
                         //cell.textLabel.text =[goingBackDates objectAtIndex:indexPath.row];
                        //cell.textLabel.text=[goingBackDates objectAtIndex:indexPath.row];
                        cell.textLabel.text =[goingBackDates objectAtIndex:indexPath.row];
                    }
                    return cell;
                }
                
                
                - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
                {
                    NSLog(@" champ séléctionner : %d ",indexPath.row);
                
                    if(segment.selectedSegmentIndex==0)
                    {
                        depSelectedIndice=indexPath.row;  
                    }
                    else if(segment.selectedSegmentIndex==1) {
                        comSelectedIndice=indexPath.row;
                    }
                    //[tableView reloadData];
                }
                
                -(IBAction) segmentedControlIndexChanged
                {
                    int i;
                    switch (self.segment.selectedSegmentIndex) 
                    {
                        case 0:
                            i=0;
                
                            [tableView reloadData];
                            break;
                        case 1:
                            i=1;
                            NSLog(@"dexieme segment selectionner");
                            [tableView reloadData];
                        default:
                            break;
                    }
                }
                

                推荐答案

                NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
                

                将为您提供当前所选行的 NSIndexPath.然后你可以做

                will give you the NSIndexPath for the current selected row. You can then do

                [tableView selectRowAtIndexPath:indexPath 
                                       animated:NO 
                                 scrollPosition:UITableViewScrollPositionMiddle];
                

                稍后选择该行(并将其显示在屏幕中间).

                to select that row (and show it in the middle of the screen) later.

                这篇关于UITableView中默认重新加载后如何记住选择的行并维护它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What values should I use for iOS boolean states?(我应该为 iOS 布尔状态使用什么值?)
                Why does Objective-C use YES/NO macro convention instead of true/false?(为什么 Objective-C 使用 YES/NO 宏约定而不是 true/false?)
                How do I get NSJSONSerialization to output a boolean as true or false?(如何让 NSJSONSerialization 将布尔值输出为真或假?)
                Is there any difference between bool, Boolean, and BOOL in Objective-C?(Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?)
                BOOL to NSString(布尔到 NSString)
                Set bool property of all objects in the array(设置数组中所有对象的布尔属性)
                  <bdo id='6jYf2'></bdo><ul id='6jYf2'></ul>
                    <tbody id='6jYf2'></tbody>
                      <i id='6jYf2'><tr id='6jYf2'><dt id='6jYf2'><q id='6jYf2'><span id='6jYf2'><b id='6jYf2'><form id='6jYf2'><ins id='6jYf2'></ins><ul id='6jYf2'></ul><sub id='6jYf2'></sub></form><legend id='6jYf2'></legend><bdo id='6jYf2'><pre id='6jYf2'><center id='6jYf2'></center></pre></bdo></b><th id='6jYf2'></th></span></q></dt></tr></i><div id='6jYf2'><tfoot id='6jYf2'></tfoot><dl id='6jYf2'><fieldset id='6jYf2'></fieldset></dl></div>
                      <tfoot id='6jYf2'></tfoot>

                      1. <small id='6jYf2'></small><noframes id='6jYf2'>

                          <legend id='6jYf2'><style id='6jYf2'><dir id='6jYf2'><q id='6jYf2'></q></dir></style></legend>