Sending a info to detailview from UICollectionView is not working? - ios

I think i didnt explain well in the title, heres the problem, I have a collection view that is supplying from a json, but when I go to the detail it crashes, i think the problem is in this part of the code when I send the info to the detail:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier]isEqualToString:#"detailView"]) {
NSIndexPath *myIndexPath = [self.collectionView indexPathsForSelectedItems];
int row = [myIndexPath row];
MenuDetailViewController *menu = [segue destinationViewController];
EntryJson *entry = [[InfoWeb sharedInstance] entryAtIndex:row];
menu.galeriademo = entry.imagenes;
menu.DetailModalprim = #[entry.title == nil ? #"" : entry.title,
entry.date == nil ? #"" : entry.date,
entry.desc == nil ? #"" : entry.desc,
entry.mainimage == nil ? #"" : entry.mainimage,
entry.seccion == nil ? #"" : entry.seccion];
}
}
In a tableview the IndexPath would be like: NSIndexPath *myIndexPath = [self.collectionView indexpathforselectedRow];
I had a tableview working like this and it was fine but when I change to a collection view i had this problem. The crash log is the next:
2014-03-07 12:41:00.696 CMT[28640:70b] -[__NSArrayI row]: unrecognized selector sent to instance 0xc34d180
2014-03-07 12:41:00.698 CMT[28640:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI row]: unrecognized selector sent to instance 0xc34d180'
So I need your help! Thanks!

indexPathsForSelectedItems returns an NSarray, not an NSIndexPath
NSIndexPath *myIndexPath = [self.collectionView indexPathsForSelectedItems];
should be
NSArray *myIndexPaths = [self.collectionView indexPathsForSelectedItems];
NSIndexPath *myIndexPath = [myIndexPahts objectAtIndex:0];

Related

Unrecognized selector sent to instance UITableView cell push to TabbarController

I'm just trying send the mid to customerDetailviewcontroller and segue is going tabbar controller first.
There is my prepareforsegue method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ApiClass *apiClass = [self.customerCards objectAtIndex:indexPath.row];
CustomerDetailViewController *customerDetailViewController = (CustomerDetailViewController *)segue.destinationViewController;
customerDetailViewController.mid = apiClass.mid;
}
}
_mid NSString * #"1642"
That is the error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setMid:]: unrecognized selector sent to instance 0x126e53580'
*** First throw call stack:
(0x1838d6530 0x1948ac0e4 0x1838dd5f4 0x1838da3ac 0x1837dec4c 0x1000ae2b4 0x1886b401c 0x18820ce14 0x1882ca6dc 0x188166b8c 0x1880d85f0 0x18388ed98 0x18388bd24 0x18388c104 0x1837b91f4 0x18cbdb6fc 0x18814a10c 0x1000e2b08 0x194f2aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
There is the data I'm getting from json.So it is not nil.
http://prntscr.com/6lzjkd
I figure out this.Main Problem I push the segue to tabbar controller.And I fixed it with this code.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ApiClass *apiClass = [self.customerCards objectAtIndex:indexPath.row];
UITabBarController *tabBarController = [segue destinationViewController];
CustomerDetailViewController *customerDetailViewController = (CustomerDetailViewController *)[[tabBarController viewControllers]objectAtIndex:0];
customerDetailViewController.mid = apiClass.mid;
}
It is trying to execute the method setMid:, but it can't find that one. Did you set the property mid as readwrite?

Error Pushing a navigation controller is not supported [duplicate]

This question already has an answer here:
Pushing data from a UITableViewCell to a UINavigationController
(1 answer)
Closed 8 years ago.
I have a UISearchDisplaycontroller that i have to push information to text fields and need to link it to a navigation view controller.
Here is the error -
2014-12-10 20:05:08.775 Contents Concepts Mobile[2785:333301] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
*** First throw call stack:
(0x2311dc1f 0x30b96c8b 0x26663207 0x268d0229 0x26662b43 0x266f2f67 0x267a4c0f 0x26656c4d 0x265d2aab 0x230e43b5 0x230e1a73 0x230e1e7b 0x23030211 0x23030023 0x2a3c00a9 0x2663c1d1 0xf0225 0x31116aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here is my code -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showRecipeDetail"]) {
NSIndexPath *indexPath = nil;
Recipe *recipe = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
recipe = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
recipe = [recipes objectAtIndex:indexPath.row];
}
RecipeDetailViewController *destViewController = segue.destinationViewController;
destViewController.recipe = recipe;
}
}
Can you also post your story board setting as well. It seems you have a linking problem between two different views. Cause the error message said you are trying to push the navigation controller and not the view controller.

Access UISwitch in Prototype Cell

I'm trying to print on/off when the user changes the state of my UISwitch.
For example
- (IBAction)toggleSwitch:(id)sender {
ChannelsTableViewCell* cell = (ChannelsTableViewCell *)[sender superview].superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
if (cell.localSwitch.on)
{
NSLog(#"On");
}
}
When I run this it throws an error.
2014-04-24 11:33:41.462 HRApp[3258:60b] -[UITableViewCellScrollView localTitle]: unrecognized selector sent to instance 0x19354410
2014-04-24 11:33:41.467 HRApp[3258:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellScrollView localTitle]: unrecognized selector sent to instance 0x19354410'
If you hook up the IBAction to the switch, you don't need to get the UITableViewCell to check for the switch's value. You can use the sender parameter from the IBAction. Hence:
- (IBAction)toggleSwitch:(id)sender {
UISwitch *switch = (UISwitch *)sender;
if (switch.on)
{
NSLog(#"On");
}
}
If you need to find the indexPath at which the UISwitch is shown, you can add the following:
CGPoint pointInTable = [switch convertPoint:switch.bounds.origin toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:pointInTable];

View Controllers giving an error when creating a segue

I have a navigation controller and the first VC modals into the second one fine. I pressed ctrl+button and dragged it over, all works fine.
I am doing a second segue from the first VC (again) and this time its another button, I am ctrl+button and dragging it to the new VC and I get an USELESS error in XCODE -
2014-03-04 11:57:21.340 OutTonight[3173:60b] -[SettingsViewController
setDealdetail:]: unrecognized selector sent to instance 0x16e686d0
2014-03-04 11:57:21.342 OutTonight[3173:60b] * Terminating app due
to uncaught exception 'NSInvalidArgumentException', reason:
'-[SettingsViewController setDealdetail:]: unrecognized selector sent
to instance 0x16e686d0'
* First throw call stack:
Here is my prepareforseguecode
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableview indexPathForSelectedRow];
DealViewController *detailView = (DealViewController *)segue.destinationViewController;
detailView.dealdetail = [self.allcontent objectAtIndex:indexPath.row];
detailView.dealpostcode = [self.allpostode objectAtIndex:indexPath.row];
detailView.dealvenuename = [self.allname objectAtIndex:indexPath.row];
detailView.dealaddress = [self.alladdress objectAtIndex:indexPath.row];
detailView.dealaddress2 = [self.alladdress2 objectAtIndex:indexPath.row];
detailView.deallat = [self.alllat objectAtIndex:indexPath.row];
detailView.deallng = [self.alllong objectAtIndex:indexPath.row];
detailView.userlatitude = [[NSUserDefaults standardUserDefaults] objectForKey:#"UserLatitude"];
detailView.userlongitude = [[NSUserDefaults standardUserDefaults] objectForKey:#"UserLongitude"];
}
Any ideas?
I assume you have done something in -prepareForSegue: for the original segue? In which case, you need to make sure you are checking which segue it is in -prepareForSegue:, and doing the correct thing for each one.
Edit:
To expand on my answer, I guess you are using segue.destinationViewController, and calling setDealdetail: on it. This probably worked fine for your initial segue, because the destinationViewController responded to that message, but, the destination for the new segue doesn't. You need to check which segue is being performed. Using [segue.identifier isEqualToString:MySegueIdentifierString];
Edit 2 (after posting code):
Ok, you need to check which segue is being performed in your -prepareForSegue:. Something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:SegueToDealViewControllerIdentifier]) {
NSIndexPath *indexPath = [self.tableview indexPathForSelectedRow];
DealViewController *detailView = (DealViewController *)segue.destinationViewController;
detailView.dealdetail = [self.allcontent objectAtIndex:indexPath.row];
detailView.dealpostcode = [self.allpostode objectAtIndex:indexPath.row];
detailView.dealvenuename = [self.allname objectAtIndex:indexPath.row];
detailView.dealaddress = [self.alladdress objectAtIndex:indexPath.row];
detailView.dealaddress2 = [self.alladdress2 objectAtIndex:indexPath.row];
detailView.deallat = [self.alllat objectAtIndex:indexPath.row];
detailView.deallng = [self.alllong objectAtIndex:indexPath.row];
detailView.userlatitude = [[NSUserDefaults standardUserDefaults] objectForKey:#"UserLatitude"];
detailView.userlongitude = [[NSUserDefaults standardUserDefaults] objectForKey:#"UserLongitude"];
}
}
Where SegueToDealViewControllerIdentifier is the segue identifier for the original segue.

Add row to UITableViewController from child

I have UIViewController that performs a login check with the code below, and a UITableViewController as its parent controller. I'm trying to add another row to the UITableViewController after switching back to it, however I'm getting the following error:
[UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0
2014-03-08 17:00:27.379 MyApp[2562:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0'
-
if(loginSuccess)
{
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController performSelector:#selector(insertNewObject:) withObject:#"Another Row"];
}
The method definition of insertNewObject is:
- (void)insertNewObject:(NSString *)name
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:name atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
Can someone help me with what I'm doing wrong?
You're calling insertNewObject on a UINavigationController not your UITableViewController.
Try creating a property on your UIViewController that points to the original TableViewController and calling it through the property. Or calling it when the TableViewController reappears.

Resources