Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在TableViewController中未更新Segue_Ios_Objective C_Uitableview_Segue - Fatal编程技术网

Ios 在TableViewController中未更新Segue

Ios 在TableViewController中未更新Segue,ios,objective-c,uitableview,segue,Ios,Objective C,Uitableview,Segue,下午好 我已经在我的TableViewController中创建了一个Segue,用户可以在其中触摸用户配置文件,并将该用户名发送到ProfileViewController,用户信息在其中加载帖子、图像、信息。。。有点像Facebook的墙 问题是,当我触摸一个用户时,它会正确显示所有内容,但当我触摸另一个配置文件图像时,它会再次显示相同的ProfileViewController,就像用户名没有更新,发送错误一样 当我触摸屏幕上的任何地方,然后再次触摸用户配置文件时,在这种情况下它会工作,但

下午好

我已经在我的TableViewController中创建了一个Segue,用户可以在其中触摸用户配置文件,并将该用户名发送到ProfileViewController,用户信息在其中加载帖子、图像、信息。。。有点像Facebook的墙

问题是,当我触摸一个用户时,它会正确显示所有内容,但当我触摸另一个配置文件图像时,它会再次显示相同的ProfileViewController,就像用户名没有更新,发送错误一样

当我触摸屏幕上的任何地方,然后再次触摸用户配置文件时,在这种情况下它会工作,但我需要在任何情况下都能工作

我将发布我的TableViewController,如果这有助于您发现问题,因为它几乎可以正常工作,我需要修复的唯一一件事是未在图像上更新的用户名点击手势识别器

序列在代码的末尾

TableViewController.m


提前谢谢。

好的,这里有一个选项。 1.删除所有现有segueprofile和segueprofile2 2.连接tableviewcontroller重要信息:不是tableview,而是控制器本身,通过push segue将其命名为segueprofile3与您的详细信息控制器连接 3.按照以下方式重构代码

@property (nonatomic, strong) NSIndexPath * selectedIndexPath;

...

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)anIndexPath {
    self.selectedIndexPath = anIndexPath;
    [self performSegueWithIdentifier:@"segueprofile3" sender:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"segueprofile3"]) {
        OtherProfileUserViewController *destViewController = segue.destinationViewController;
        destViewController.recipeName = [[_jsonArray objectAtIndex:selectedIndexPath.row] valueForKey:@"username"];
    }
}

另一种选择。将UIButton控件置于avatar UIImageView上方。在CarTableViewCell类中创建关联的IBOutlet并建立outlet连接

@property (nonatomic, weak) UIButton * btnAvatar;
接下来,修改CarTableViewController代码

//1. declare new propery
@property (nonatomic, strong) id selectedProfile;

//2. implement future button tap handler
-(IBAction) btnAvatarDidPress:(id) sender {
  int tag = ((UIButton *) sender).tag;
  self.selectedProfile = [_jsonArray objectAtIndex:tag];
  [self performSegueWithIdentifier:@"segueprofile3" sender:nil];
}


//Extend your cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"carTableCell";

    CarTableViewCell *cell = [tableView
                              dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[CarTableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.makeLabel.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"id"];
    cell.btnAvatar.tag = indexPath.row;
... rest of method
}
然后移除didSelectRowAtIndexPath方法,并将btnAvatar触动内部操作连接到控制器代码内的btnAvatarDidPress方法。
我希望我什么也没忘记。

以下是您的示例,在PrepareForsgue中,获取按钮所在的单元格:

id v = sender;
while (![(v= v.superView) isKindOfClass:[UITableViewCell class]] 
       && v!=nil) ;
if (v==nil) 
  // no ancestor view is cell.
else{
  // now v is the cell.
  NSIndexPath * indexPath = [self.tableView indexPathForCell:v];
  // do the left
}

我觉得selectedRow可能没有更新。您可以使用sender来定位行并获取数据。我建议使用didSelectRowAtIndexPath委托方法并手动从中执行segue。在我看来,这个序列似乎更稳定。嗨@heximal,你能给我举个例子吗?我对Objective-C相当陌生,我不知道如何做到你所说的。非常感谢。是的,当然,请给我一点时间,我会为你谱写。嗨@SolaWing,我怎么能做到?你能给我举个例子吗?您好。谢谢@heximal,这意味着当我点击整行时,不仅在配置文件图像上,还将启动到ProfileViewController的Segue?我需要这只是对图像配置文件和图像名称的工作,因为我已经有一个序列使用行点击手势,它打开了这篇文章与更多的信息。好的,这不是一个问题,大部分代码和IB的变化仍然是实际的。您只需在UIImageView上点击并运行相同的segue即可。如果你有一个简单的平面表结构,你可以通过使用标记属性将UIImageView与indexPath关联起来,标记属性是整数,你可以在创建TableCell时分配它。我将尝试一下你所说的,但是如果你能提供一点帮助,我将不胜感激,因为我已经告诉过你,我不是专家,目前一切都很困难。你能给我举一些你所说的例子吗?再次感谢@heximalyes,当然,只是我需要多一点时间来展示它。onOK:,非常感谢@heximal。
id v = sender;
while (![(v= v.superView) isKindOfClass:[UITableViewCell class]] 
       && v!=nil) ;
if (v==nil) 
  // no ancestor view is cell.
else{
  // now v is the cell.
  NSIndexPath * indexPath = [self.tableView indexPathForCell:v];
  // do the left
}