我们可以在didSelectRowAtIndexPath?
之后制作像prepareForSegue这样的排名吗?我的NSLog发送了一个很好的句子,这个NSLog就是我想要的(在didSelectRowAtIndexPath中,但在prepareForSegue中为我的NSLog分配AFTER)我希望prepareForSegue中的NSLog发送与didSelectRowAtIndexPath相同的句子。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
self.cellSelected = cell.textLabel.text;
NSLog(@"la : %@", self.cellSelected);
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showPhotoView"]) {
NSLog(@"ou %@", self.cellSelected);
PhotoViewController *viewController = (PhotoViewController *)segue.destinationViewController;
viewController.cellSelected = self.cellSelected;
}
}
答案 0 :(得分:2)
是的,你可以!你只需修理一些东西
以下是我使用的示例
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"friends2" sender:self];
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"friends2"]) {
NSString * object = nil;
NSIndexPath *indexPath2 = nil;
if (self.searchDisplayController.isActive) {
indexPath2 = [[ self.searchDisplayController searchResultsTableView]indexPathForSelectedRow];
object = self.results[indexPath2.row];
NSLog(@"is active : %@", object.self);
} else
{
indexPath2 = [self.tableView indexPathForSelectedRow];
object = sortedArray.self[indexPath2.row];
NSLog(@"is not active : %@", object.self);
}
使用didSelect ..我刚刚制作了segue,并且通过performSegue你可以做你想做的事情
答案 1 :(得分:2)
如果使用源自UITableViewCell的segue,sender
参数实际上将包含所选的UITableViewCell。因此,您可以使用sender参数来获取所需的数据。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showPhotoView"]) {
UITableViewCell *cell = sender;
PhotoViewController *viewController = (PhotoViewController *)segue.destinationViewController;
viewController.cellSelected = cell;
}
}