I have an issue with segue when clicking on cell and trying to transfer my date to DetailViewController
I didn't find here answers to my question, so I am asking here.
Here is my Method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// NSLog(#"Source Controller = %#", [segue sourceViewController]);
// NSLog(#"Destination Controller = %#", [segue destinationViewController]);
// NSLog(#"Segue Identifier = %#", [segue identifier]);
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if (indexPath){
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
NSLog(#"%#", item.title);
}
}
if I will remove if condition only
and leave my code like this one:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// NSLog(#"Source Controller = %#", [segue sourceViewController]);
// NSLog(#"Destination Controller = %#", [segue destinationViewController]);
// NSLog(#"Segue Identifier = %#", [segue identifier]);
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
NSLog(#"%#", item.title);
}
my data can be transferred but only always first cell.
If I will implement it like this one:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"detailNews"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//if (indexPath){
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
NSLog(#"%#", item.category);
}
}
it will send but always a title of news and always from first news. (NSLOG only for checking)
I know it receives all values, I have checked it by NSLOG, not only the title.
For your information I have always latest 20 news parsed from web site
That's working and my cells filled by news titles.
Could you please suggest me where I am wrong?
Thank you
if "sender" is the cell that's calling this, you can do:
NSIndexPath *indexPath = [[self tableView] indexPathForCell:sender];
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
Ok I think I solved my last issue. I have forgotten connect my IBOUTLET Tableview to my viewcontroller. That's it
Related
Can we make a rank like prepareForSegue after didSelectRowAtIndexPath?
My NSLog sends a good sentence, this NSLog is that I want (in didSelectRowAtIndexPath but assign AFTER to my NSLog in prepareForSegue) I would like the NSLog in prepareForSegue sends the same sentence that 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;
}
}
If you use a segue that originates from a UITableViewCell the sender parameter will actually contain the UITableViewCell that was selected. So you could just use the sender parameter to get the data you need.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"showPhotoView"]) {
UITableViewCell *cell = sender;
PhotoViewController *viewController = (PhotoViewController *)segue.destinationViewController;
viewController.cellSelected = cell;
}
}
Yes you can ! You need just to fix some things
Here is an example i used
- (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);
}
with didSelect.. i just made the segue, and with performSegue you do what you want to do
i am using parse as the backend, i tried to output the below with NSlog, but i keep getting the same object id, please help
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"MoreDetails"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
MoreDetailsViewController *destVC = segue.destinationViewController;
PFObject *object = [self.objects objectAtIndex:indexPath.row];
NSString *objectId = [object objectId];
Offers *offers = [[Offers alloc]init];
offers.offerID = objectId;
destVC.offer = offers;
NSLog(#"table view %#", objectId);
}
}
With segues linked from storyboard cells, the cell may not be selected at the point the segue is prepared for.
Luckily, you have access to the cell itself because it is the sender of the segue.
Change this line of code:
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
To
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
This will give you the correct index path.
Im having trouble passing a string to a second view. I am trying to grab the indexpath.row for the selected tableviewcell and pass the associated string but keep getting "unrecognized selector.."
When using DLog the console displays the correct string. On the view im passing info. to I have an NSString setup. Thanks for any help you can provide!
Here is the prepareforsegue code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"kShowMovie"])
{
MoviePlayerNEWViewController *dvc = (MoviePlayerNEWViewController *)[segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DemoVideos *demovideo = [_tableContents objectAtIndex:indexPath.row];
dvc.videoDemoString = demovideo.vd_link;
DLog(#"Video link to pass = %#",demovideo.vd_link);
}
UIViewController * controller = segue.destinationViewController;
[controller setHidesBottomBarWhenPushed:YES];
}
The error message is saying that the controller you're trying to call setVideoDemoString: on is a UINavigationController, not a MoviePlayerNEWViewController as you think it is. You probably want this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"kShowMovie"])
{
UINavigationController *nav = segue.destinationViewController;
MoviePlayerNEWViewController *dvc = nav.topViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DemoVideos *demovideo = [_tableContents objectAtIndex:indexPath.row];
dvc.videoDemoString = demovideo.vd_link;
DLog(#"Video link to pass = %#",demovideo.vd_link);
}
UIViewController * controller = segue.destinationViewController;
[controller setHidesBottomBarWhenPushed:YES];
}
I use segues for both push on cell and detail disclosure button.
I can't tap on indices, because detail disclosure button "intercepts" touch instead.
Code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
if ([segue.identifier isEqualToString:#"Dossier Segue"]) {
Person *person = [[self fetchedResultsController] objectAtIndexPath:indexPath];
DSRevealViewController *vc = (DSRevealViewController *)segue.destinationViewController;
vc.person = person;
vc.transitioningDelegate = self;
}
else if ([segue.identifier isEqualToString:#"Info"]) {
Person *person = [[self fetchedResultsController] objectAtIndexPath:indexPath];
NSAssert(person, #"Person is nil");
PersonInfoViewController *vc = (PersonInfoViewController *)segue.destinationViewController;
vc.person = person;
}
}
P.S. I checked my other app where I use table view delegate methods instead of segues, and it works well.
I'm trying to change the destination of a button using the selected Row of a tableViewCell.
How would I do that? I know how to change the text in a UILabel. Would it be something like that? I'm using this in my MainView to get to the DetailView:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"toDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *destViewController = segue.destinationViewController;
destViewController.nameIdentity = [nameData objectAtIndex:indexPath.row];
}
}
And in my DetailView.m:
{
[super viewDidLoad];
nameLabel.text = nameIdentity;
}
I used a NSArray for my data. Is that the correct way to go for the numbers as well?
I`m using X-Code 4.6, Objective-C, Storyboard.
Could this work? (I can't test it on an actual Device yet)
MainView.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"toDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *destViewController = segue.destinationViewController;
destViewController.numberIdentity = [numberData objectAtIndex:indexPath.row];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
numberData = [NSArray arrayWithObjects:/*1*/#"5552525",/*2*/#"5553456", nil];
}
DetailView.m
-(IBAction)callCell {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:numberIdentity]];
}
How can I fire a message to the debugger?