Unrecognized selector - using indexpath.row to send a string to view2 - objective-c

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];
}

Related

The indexPath of custom table cell is undefined, objective c

I have created a custom cell call PendingDoctorTableViewCell and is used in PendingDoctorTableView. Everything is work find and i added a disclosure indicator by using
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
It's able to performed the segue "ShowPendingDoctor".
However when i used the prepareForSegue, the indexPath is undefined.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ShowPendingDoctor"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ActionForPendingDoctorViewController *destViewController = segue.destinationViewController;
destViewController.myObjects = [myObject objectAtIndex:indexPath.row];
// Hide bottom tab bar in the detail view
// destViewController.hidesBottomBarWhenPushed = YES;
}
}
How can i get to know which row had been tap. because its always return the object of 1st index.
Anyone can help me? i'm rushing for my project. Thanks.
Declare a variable of NSIndexPath to save your currently selected indexPath
NSIndexPath *selectedIndexPath;
Use Tableview delegate to identify selected row and perform segue programmatically
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:YOUR_SEGUE_IDENTIFIER sender:self];
}
Pass your object to next ViewController through prepareForSegue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:YOUR_SEGUE_IDENTIFIER])
{
ActionForPendingDoctorViewController *destViewController = segue.destinationViewController;
destViewController.myObjects = [myObject objectAtIndex:selectedIndexPath.row];
}
}

self.tableView indexPathForSelectedRow returns nil

I'm fairly new to Objective-C and have encountered this following issue.
I've setup the storyboard and the linked up the view controllers accordingly. Also, setup the segue. However, for some weird reason, self.tableView indexPathForSelectedRow is returning me nil.
Really appreciate for the help in advanced!
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if([[segue identifier] isEqualToString:#"infoTherapyCloseCase"])
{
infoTherapyPhaseCloseCaseViewController *info = [segue destinationViewController];
//info = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
TherapyPhases *tp = _DetailModal[row];
info.DetailModal = #[tp];
}
}

how do i return unique objectID when i prepareForSegue on iOS 7

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.

Change data of a button according to selected Row in TableView

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?

PrepareForSegue Tableview issue

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