Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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 调用自定义单元格的didSelectRowAtIndex_Ios_Xcode_Uitableview_Uibutton - Fatal编程技术网

Ios 调用自定义单元格的didSelectRowAtIndex

Ios 调用自定义单元格的didSelectRowAtIndex,ios,xcode,uitableview,uibutton,Ios,Xcode,Uitableview,Uibutton,我有一个单元格,它有两个UIButton属性(nameLabel和profileImageButton),用于查看帖子的用户配置文件页面。我正在尝试从当前单元格获取用户,但未调用DidSelectRowatinex。我意识到这是应该发生的(方法没有被调用),但我不知道如何绕过它 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object

我有一个单元格,它有两个UIButton属性(nameLabel和profileImageButton),用于查看帖子的用户配置文件页面。我正在尝试从当前单元格获取用户,但未调用DidSelectRowatinex。我意识到这是应该发生的(方法没有被调用),但我不知道如何绕过它

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
postCell *cell = (postCell *)[tableView dequeueReusableCellWithIdentifier:@"postCell"];

cell.personStringPost.text = [object objectForKey:@"stringPost"];
[cell.nameLabel setTitle:[object objectForKey:@"User_Name"] forState:UIControlStateNormal];
cell.userId = [object objectForKey:@"userId"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

PFFile *imageFile = [object objectForKey:@"profileImage"];
NSData *data = [imageFile getData];
cell.profileImage.image = [UIImage imageWithData:data];

cell.nameLabel.tag = indexPath.row;
[cell.nameLabel addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
[cell.profileImageButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
postCell *cell = (postCell *)[tableView cellForRowAtIndexPath:indexPath];
self.userId = cell.userId;
NSLog(@"Did Select: %@", self.userId);
}

- (void) buttonPressed: (id) sender{
UIButton *button = (UIButton *)sender;
NSInteger row = button.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
[self performSegueWithIdentifier:@"personProfile" sender:self];
}
//选择和取消选择行。这些方法
不会调用委托方法(-tableView:WillSelectRowatineXpath:或tableView:DidSelectRowatineXpath:),也不会发送通知

因此,将按下的按钮中的
selectRowAtIndexPath
替换为以下两行:

postCell *cell = (postCell *)[tableView cellForRowAtIndexPath:indexPath];
self.userId = cell.userId;

为什么要调用didSelectRow,因为您正在使用button方法执行序列?如果您知道“当前单元格”是什么,您就不能从中获取用户吗?因为我需要将数据从当前单元格传递到下一个视图控制器。我不知道现在的手机是什么,这是我的问题。当我按下按钮时,没有调用didSelectRowAtIndexPath,因此我不知道单元格数据是什么@HotLicks@rdelmar我需要从所选单元格获取数据您不应该从单元格获取数据。按钮的标记将显示选定的行。你应该用它作为数组的索引来填充表。这是非常糟糕的做法。应该从数据源访问用户ID。
postCell *cell = (postCell *)[tableView cellForRowAtIndexPath:indexPath];
self.userId = cell.userId;