【问题标题】:prepareForSegue Function not returning original switch results after searchprepareForSegue 函数搜索后不返回原始开关结果
【发布时间】:2012-11-17 14:39:29
【问题描述】:

在我的 tableview 上执行搜索并选择一行后,详细视图控制器 (MOVdetailViewController) 仅更新名称而不更新信息(地址、网站和其他内容)。它位于我设置为开关的 MDVC.lodgeNumber 中。我现在认为这是不可能的,因为详细信息存储在开关中。非常感谢所有反馈

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{
  if ([segue.identifier isEqualToString:@"lodgedetail"]) {
      MOVDetailViewController *destViewController = segue.destinationViewController;
      MOVDetailViewController * MDVC = [[MOVDetailViewController alloc] init];


      NSIndexPath * path = [self.tableView indexPathForSelectedRow];
      NSString * thelodge = [filteredList objectAtIndex:path.row];

      MDVC = [segue destinationViewController];
      MDVC.lodgeNumber = path.row;
      MDVC.lodgeName = thelodge;



      NSIndexPath *indexPath = nil;

      if ([self.searchDisplayController isActive]) {
          indexPath = [self.searchDisplayController.searchResultsTableView
                          indexPathForSelectedRow];
          destViewController.lodgeName = [filteredList objectAtIndex:indexPath.row];



      } else {
          indexPath = [self.tableView indexPathForSelectedRow];
          destViewController.lodgeName = [lodgeList objectAtIndex:indexPath.row]; 
        }
      }
   }

开关示例:

  self.title = lodgeName;     
  switch (lodgeNumber) {
      case 0:
          //Abingdon Lodge No. 48
          address.text = @"325 W Main Street Abingdon, Virginia 24210";
          website.text = @"http://www.grandlodgeofvirginia.org/lodges/48/";
          statedc.text = @"Abingdon Lodge No. 48 holds it's stated communication on the              
                           2nd Monday of the month at 7:30 PM. If there are
                            any exceptions to the regular meeting day or time, 
                            they are posted on the Lodge website.";

         lodgehistory.text = @"According to the earliest records the Abingdon Lodge had 
              its origin “At a meeting held at the house of
              James White in the town of Abingdon, on October 3, 1796.” The record
              states that a dispensation had been given by the Grand Master of
              Masons in Virginia and the following were present: William King,
              Master; Daniel Murphy, Past Master; Robert Johnson, Past Master;
              Charles Carson, Past Master, and William Preston Skillern. For more
              information on the Lodge History please see the Lodge website.";

         break;

【问题讨论】:

  • Zaheer Ahmed,你知道这是否可能吗?
  • 哪个方法包含switch 语句?
  • (lodgeNumber)....tableview 包含旅馆的名称,详细视图包含 LodgeNumber,其中包含在用户执行搜索后未更新的信息。切换方法是 (lodgeNumber) 但是 self.title AKA lodgeName 正在正确更新。我不确定为什么其他数据不是。确定执行后,详细数据仅显示案例 0,而不显示其他案例。
  • lodgeNumber 是一个数字,而不是一个方法。 (查找“方法”一词的 Objective-C 定义。)
  • 嗨,菲利普,(我是新来的,我猜你现在已经明白了)。感谢您的反馈。我想我真的不明白这对我有什么帮助。该开关的标题为 LodgeName,它保存了我在搜索完成后尝试传递给 DVC 的关键信息。它在执行搜索之前有效,但在搜索之后无效。再次感谢。现在是一种 Ill 查找方法。

标签: iphone objective-c xcode ipad


【解决方案1】:
    MOVDetailViewController *MDVC = segue.destinationViewController;
NSIndexPath * path = [self.tableView indexPathForSelectedRow];
NSString * thelodge = [filteredList objectAtIndex:path.row];

MDVC.lodgeName = thelodge;
MDVC = [segue destinationViewController];  // REMOVE THIS LINE
MDVC.lodgeNumber = path.row;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    相关资源
    最近更新 更多