<bdo id='2UAal'></bdo><ul id='2UAal'></ul>

  1. <small id='2UAal'></small><noframes id='2UAal'>

      <legend id='2UAal'><style id='2UAal'><dir id='2UAal'><q id='2UAal'></q></dir></style></legend>
      <tfoot id='2UAal'></tfoot>

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

      在 UITableView List segue 之间传递索引号

      时间:2023-05-30
        <bdo id='cIbYR'></bdo><ul id='cIbYR'></ul>
          <tbody id='cIbYR'></tbody>

          <tfoot id='cIbYR'></tfoot>

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

            <legend id='cIbYR'><style id='cIbYR'><dir id='cIbYR'><q id='cIbYR'></q></dir></style></legend>
          • <small id='cIbYR'></small><noframes id='cIbYR'>

                本文介绍了在 UITableView List segue 之间传递索引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                当我单击 UITableView 中的某个列表项时,我想将单击的项的索引传递给下一个详细视图.

                When I click a certain list item in my UITableView, I want to pass the index of the item that I clicked on to the next detailed view.

                到目前为止,这是我的相关代码:

                This is my relevant code so far:

                 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
                {
                    HomeworkDetails *view =  [[HomeworkDetails alloc] init];
                
                
                    int lastIndex = [indexPath indexAtPosition:[indexPath length] - 1];
                    NSLog(@"%u", lastIndex);
                
                    [self performSegueWithIdentifier: @"HomeworkDetailsSegue" sender:self];
                    view.currentIndex = lastIndex;
                
                    [tableView deselectRowAtIndexPath:indexPath animated:YES];
                
                }
                

                此时,我可以成功移动到下一个ViewController(HomeworkDetails)但信息没有通过.我正在尝试通过执行 view.currentIndex = lastIndex; 来完成此操作,但这不起作用.我还能怎么做?对不起,如果我错过了什么;我是 iOS 开发的初学者.

                At this point, I can successfully move on to the next ViewController (HomeworkDetails) but the information is not passed through. I am trying to accomplish this by doing view.currentIndex = lastIndex; but this is not working. How else can I do this? Sorry if I missed anything; I am a beginner at iOS development.

                有建议:

                - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
                {
                
                
                    HomeworkDetails *view =  [[HomeworkDetails alloc] init];
                
                
                    int lastIndex = [indexPath indexAtPosition:[indexPath length] - 1];
                    NSLog(@"%u", lastIndex);
                
                    [self performSegueWithIdentifier: @"HomeworkDetailsSegue" sender:self];
                    view.currentIndex = lastIndex;
                
                    [tableView deselectRowAtIndexPath:indexPath animated:YES];
                
                
                
                }
                
                
                - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
                {
                    if ([segue.identifier isEqualToString:@"HomeworkDetailsSegue"]) {
                
                        // note that "sender" will be the tableView cell that was selected
                        UITableViewCell *cell = (UITableViewCell*)sender;
                       NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; //**error**
                
                
                        HomeworkDetails *vc = (HomeworkDetails*)[segue destinationViewController];
                        vc.currentIndex = indexPath.row;
                    }
                }
                

                推荐答案

                您所描述的最好在 prepareForSegue:sender: 方法中完成,而不是 didSelectRowAtIndexPath:.在您的故事板中,确保您的 HomeworkDetailsS​​egue segue 设置在 tableView 的原型单元格和目标视图控制器之间.

                What you are describing can best be done in the prepareForSegue:sender: method, instead of didSelectRowAtIndexPath:. In your storyboard, make sure your HomeworkDetailsSegue segue is set up between your tableView's prototype cell and the destination view controller.

                - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
                {    
                    if ([segue.identifier isEqualToString:@"HomeworkDetailsSegue"]) {
                
                        // note that "sender" will be the tableView cell that was selected
                        UITableViewCell *cell = (UITableViewCell*)sender;
                        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
                
                        HomeworkDetails *vc = (HomeworkDetails*)[segue destinationViewController];
                        vc.currentIndex = indexPath.row;
                    }
                }
                

                另外,作为风格问题,我建议将您的 HomeworkDetails 类重命名为 HomeworkDetailsViewController.这样做更符合 Apple 的约定,并更清楚地说明类代表什么.

                Also, as a matter of style, I would recommend renaming your HomeworkDetails class to HomeworkDetailsViewController. Doing this follows Apple's conventions more closely and makes it clearer what the class represents.

                这篇关于在 UITableView List segue 之间传递索引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:是否可以结合非 ARC 和 ARC 项目代码? 下一篇:JSONValue ARC 问题

                相关文章

                最新文章

                • <bdo id='vrvtA'></bdo><ul id='vrvtA'></ul>

                <legend id='vrvtA'><style id='vrvtA'><dir id='vrvtA'><q id='vrvtA'></q></dir></style></legend>
                    <tfoot id='vrvtA'></tfoot>
                  1. <small id='vrvtA'></small><noframes id='vrvtA'>

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