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.
Related
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?
I have a custom UITableViewCell with a class linked to it called customCell.m. (I didn't use xib.) In the cell there is a button. Is there a way to create the buttons action on the mainVC.m file, as apposed to customCell.m?
Update
Here is the code I tried implementing. What I did is, I called a method from mainVC.m.
CustomCell.m
- (IBAction)myButton:(id)sender
{
CategorieViewController *mainVC = [[CategorieViewController alloc] init];
[mainVC myMethod];
}
MainVC.m
- (void)myMethod:(id)sender
{
UITableViewCell *clickedCell = (UITableViewCell *)[[[sender superview] superview] superview];
NSIndexPath *clickedButtonPath = [self.myTableView indexPathForCell:clickedCell];
NSLog(#"%#", clickedButtonPath);
}
CategorieViewController myMethod]: unrecognized selector sent to instance 0x7fd2dbd52a00
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategorieViewController myMethod]: unrecognized selector sent to instance 0x7fd2dbd52a00'
You're calling myMethod, but the method is actually myMethod: and takes the sender as a parameter. Try changing:
[mainVC myMethod];
to:
[mainVC myMethod:sender];
Also, any sender you currently pass to myMethod: as a parameter, won't belong to mainVC's tableview yet because you're creating a brand new CategorieViewController instance to perform the method call and its table has never been loaded.
Assuming MainVC is the visible view controller, you can change:
CategorieViewController *mainVC = [[CategorieViewController alloc] init];
to:
UINavigationController *nav = (UINavigationController*)self.window.rootViewController;
CategorieViewController *mainVC = (CategorieViewController*)nav.visibleViewController;
to get the current the current MainVC instance with the loaded tableview.
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.
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];
i have a TableView which loads a detailview in didSelectRow. I have no problems with the data's.
I am using coreData and to populate the TableView i am using a NSFetchedResultsController.
Now, i want to make a next and previous function in the detailView to jump to the next or previous Table(row) Element. Next Previous like in the Mail-App.
I know that i have to use a button with IBAction.
But how can i make this function?
thanks,
brush51
Edit 1:
I have it done so:
- (IBAction) previousCard:(id) sender {
NSLog(#"previousBtn");
DashboardViewController *parent = (DashboardViewController *)self.parentViewController;
NSIndexPath *actualIndexPath = selectedRow2;
NSIndexPath * newIndexPath = [NSIndexPath indexPathForRow:actualIndexPath.row-1 inSection:actualIndexPath.section];
NSLog(#"newIndexPath: %#", newIndexPath);
[parent.tableViews selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; //HERE I GET SIGABRT
}
But i get an error:
-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0'
How to solve this?
With your UITableView, you can get the selected row by:
- (NSIndexPath *)indexPathForSelectedRow
And set the selection by incrementing the indexPath.row:
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
then you action could be:
-(IBAction)nextCell:(id)sender {
NSIndexPath * actualIndexPath = myTableView.indexPathForSelectedRow;
NSIndexPath * newIndexPath = [NSIndexPath indexPathForRow:actualIndexPath.row+1 inSection:actualIndexPath.section];
[myTableView selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
for that you can manage with your DataSource array.
when you load your detail view at that time you pass your index of array(indexPath.row). by that index you fetch data in detail view. and using increment and decrement in that index you get data for next and previous cell.
Steps
1) setup your tableView.
2) when redirect to DetailView at that time set one int variable for store current indexPath.row . so define one int in detail View.
3) using next and previous button manage indexpath.row which is in int variable.
and represent appropriate data from Source array.
You can use:
(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
To get the cell you want (next or previous).
And then set the returned cell "Selected" property to YES.
cell.selected = YES