Tapping on indexes doesn't work - objective-c

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.

Related

Passing indexPath from UITableView

In my application I have oneUITableViewController (Uctovatrida0TableViewController) and two otherUIViewContoller (DetailViewController and examples).
Now I have a problem because I do not know how to identify index (from indexPath.row) in my firstUIViewController to then correctly referred to another UIViewController.
The code in my Uctovatrida0TableViewController.m (works well):
-(void) showDetailsForIndexPath:(NSIndexPath*)indexPath
{
[self.searchBar resignFirstResponder];
DetailViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailsViewController"];
Ucty* ucet;
if(isFiltered)
{
ucet = [_filteredTableData objectAtIndex:indexPath.row];
}
else
{
ucet = [self.alldataArray objectAtIndex:indexPath.row];
}
vc.uctyItem = ucet;
[self.navigationController pushViewController:vc animated:true];
}
Code in my class DetailViewConroller where I need indexPath from Uctovatrida0TableViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"Priklad"])
{
Priklad *vc = [segue destinationViewController];
Ucty* ucet;
//of course this does not work
ucet = [self.alldataArray objectAtIndex:NSIndexPath.row];
vc.uctyItem = ucet;
[self.navigationController pushViewController:vc animated:true];
}
}
Code in my class Priklad.m:
- (void)setDetailItem:(id)newDetailItem
{
if (self.uctyItem != newDetailItem)
{
self.uctyItem = newDetailItem;
[self configureView];
}
}
- (void)configureView
{
if (self.uctyItem ) {
self.prikladLabel.text = self.uctyItem.priklad;
self.uctykprikladu.text = self.uctyItem.uctykprikladu;
}
}
From your code, it seems DetailViewConroller has a property uctyItem. So in your DetaiViewController's prepareForSegue:sender: method, you can just call vc.uctyItem = self.uctyItem;.
Add a property to DetailViewConroller that you can set before pushing to it.
#property (assign, nonatomic) int index;
If you want to get selected cell indexPath then there is a method for that is : selectedIndexPath = [tableView indexPathForSelectedRow];

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

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

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

Storyboard Preparing for Seque+Passing over data

I have a detail view controller that is hooked up to a table view cell. I have a data model. It is an NSObject and has a NSMutableArray will all my properties I need in them.
I hooked up a label to an #property and named it questionLabel. For some reason, when I push over to the detail view, it does not display the question I put in the data model for the NSMutableArray.
At first I thought the segue was not working, but when I tried to change the navigation bar title, it worked when I passed my data from my NSMutableArray.
Anyone know what I am doing wrong with my label?
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"pushDetail"])
{
// Create an instance of our DetailViewController
DetailQuestionViewController *DQV = [[DetailQuestionViewController alloc] init];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
// Setting DQV to the destinationViewController of the seque
DQV = [segue destinationViewController];
Question *selectedQuestion = [self.myQuestionList questionAtIndex:path.row];
DQV.questionLabel.text = [selectedQuestion questionName];
DQV.navigationItem.title = [selectedQuestion questionRowName];
}
}
UPDATE (For: adambinsz)
Table view
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"pushDetail"])
{
// Create an instance of our DetailViewController
DetailQuestionViewController *DQV = [[DetailQuestionViewController alloc] init];
// Setting DQV to the destinationViewController of the seque
DQV = [segue destinationViewController];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
Question *selectedQuestion = [self.myQuestionList questionAtIndex:path.row];
DQV.detailItem = selectedQuestion;
}
}
detailView
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
Question *theQuestion = (Question *)self.detailItem;
self.questionLabel.text = theQuestion.questionName;
NSLog(#"The Question's questionName is %#", theQuestion.questionName);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
The reason I think it may not be working, is because the if statement for self.detailItem is not checking it correctly.
The method gets called just not the detailItem.
Your label probably hasn't been created yet when you try to set its text. I would create a selectedQuestion instance variable on DetailQuestionViewController and set it when you create the view controller. Something like this:
// Create an instance of our DetailViewController
DetailQuestionViewController *DQV = [[DetailQuestionViewController alloc] init];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
// Setting DQV to the destinationViewController of the seque
DQV = [segue destinationViewController];
DQV.selectedQuestion = [self.myQuestionList questionAtIndex:path.row];
And in DetailQuestionViewController's viewDidLoad method, set your label's text by using:
self.questionLabel.text = [selectedQuestion questionName];
self.navigationItem.title = [selectedQuestion questionRowName];