iOS MasterDetail app inside TabController - where to start? - objective-c

Really basic question here:
I want to build an app that has a bunch of MasterDetail views that can be accessed from a TabView.
I'd like to start with the MasterDetail project template, but if I do that and toss a TabController onto the front of the storyboard, I get a crash.
2012-04-08 12:51:21.205 SMToolkit[22630:fb03] -[UISplitViewController topViewController]: unrecognized selector sent to instance 0x82491c0
2012-04-08 12:51:21.208 SMToolkit[22630:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISplitViewController topViewController]: unrecognized selector sent to instance 0x82491c0'
*** First throw call stack:
(0x16ad022 0x183ecd6 0x16aecbd 0x1613ed0 0x1613cb2 0x2bf9 0x16386 0x17274 0x26183 0x26c38 0x1a634 0x1597ef5 0x1681195 0x15e5ff2 0x15e48da 0x15e3d84 0x15e3c9b 0x16c65 0x18626 0x2a6d 0x29d5)
terminate called throwing an exception(lldb)
All I've done so far is in the storyboard (literally I made a new MasterDetail project, then went into the storyboard and put a tabcontroller in front of it)

Simple answer is that the template provided for you in Master Detail includes some code you probably don't want.
In AppDelegate.m look for the following method and simply have it return YES;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}

Related

Error when selecting photo when calling ABNewPersonViewController in iPad

I managed to push an ABNewPersonViewController to my navigation controller. However I encountered this error when I'm selecting "Add photo" -> "Choose Photo":
* Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
This error is caused to due the fact that I want my iPad application to have landscape-only orientation.
Any idea how to solve this problem ? Many thanks !
Hope this helps anyone who has problem with this:
# App Delegate, add this line of code
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
# Your view, add this line of code
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
This will make Photo selector view thinks that it has UIInterfaceOrientationMaskPortrait, and yet the application still remains as landscape! Voila!

UITableViewController crash on iOS6 simulator

I'm working on a project and just update to Xcode 4.5 and i'm using iOS 6 simulator.
Now i'm getting the following error:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UITableViewController
loadView] loaded the "FeedController" nib but didn't get a
UITableView.'
It's strange cause I do not have any NIB file for this controller since it is only a table:
#interface FeedController : UITableViewController <EGORefreshTableHeaderDelegate>
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
#end
This controller is loaded from a Tab Controller, it alloc the FeedController without problem, but when you press the tab button to show the feed it crashes with that error.
It was working good on ios4 and ios5 simulators and devices.
Clean & Build project didn't help.
Anyone with same problem?
Does the answer listed here help? nib but didn't get a UITableView
If not, is your UITabBarController created from a NIB that somehow specifies a non-UITableView view for the FeedController tab?
You'll have to add this:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

Can I have a block of code run only if user is on iPhone vs iPad?

I have a master-detail app that is working great for the iPad. However, the iPhone version doesn't work because a variable that is being sent to the DetailViewController in the iPad version doesn't send to the iPhone DetailViewController. I can fix this with a single line of code in MasterViewController implementation:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
self.detailViewController=segue.destinationViewController;
}
Unfortunately, when I implement that code, the iPad version stops working. I get an exception when I go from another view controller (HomeViewController) back to DetailViewController. That error log is:
2012-07-14 14:29:12.924 46 Tracker[2772:11603] -[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0
2012-07-14 14:29:12.925 46 Tracker[2772:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0'
*** First throw call stack:
(0x148a022 0x201acd6 0x148bcbd 0x13f0ed0 0x13f0cb2 0x2cb0 0x2d75c5 0x2d77fa 0xb6c85d 0x145e936 0x145e3d7 0x13c1790 0x13c0d84 0x13c0c9b 0x16a07d8 0x16a088a 0x246626 0x1fdd 0x1f45)
terminate called throwing an exception(lldb)
So, is there any way I can run that first block of code only when the user is on the iPhone? Or, can I fix the code to make it work properly on both devices?
Here is a link to my iPad storyboard to (hopefully) make it more clear. I have a problem when I click on a table cell AFTER going from HomeViewController back to DetailViewController: http://www.grapekeeper.com/storyboards.png
Perhaps the following?
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// perform iPad logic
} else {
// perform iPhone logic
}

Button Click Gives Different Errors On Subsequent Launches

I've never seen this response before, where the same action, on different runs of the same app throws different errors.
I have an IBAction for a button (that just logs sender) in an NSViewController subclass that throws the errors upon clicking the button (this is an OSX app). I'm getting these (so far):
-[NSArrayM buttonClick:]: unrecognized selector sent to instance
-[__NSCFDictionary buttonClick:]: unrecognized selector sent to instance
-[__NSCFSet buttonClick:]: unrecognized selector sent to instance
-[NSRunLoop buttonClick:]: unrecognized selector sent to instance
And, the dreaded EXC_BAD_ACCESS.
The only code in this test app is this in the app delegate to instantiate the view controller:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
TestController *controller = [[TestController alloc] initWithNibName:#"TestController" bundle:nil];
[self.window.contentView addSubview:controller.view];
}
And this IBAction in the view controller subclass:
-(IBAction)buttonClick:(id)sender {
NSLog(#"%#",sender);
}
The IBAction which is implemented in the view controller is connected in IB (through File's Owner) to the button which is in its view.
I can't understand how I can get so many different error messages in such a simple program. Could this be a problem with the view controller not being in the responder chain? If so, why should it throw errors, shouldn't the message just get sent up the chain and then be discarded?
I've tried having the controller's view set the controller as the next responder (with [controller.view setNextResponder:controller];), but that just gives me the EXC_BAD_ACCESS error upon launch.
Ok, I fixed this with a pointer from Shane Stanley over at MacScripter (I had made another version in ApplescriptObjC to ask the question over there, but that version worked). It's a matter of memory management -- too easy to forget about that when using ARC. The TestController instance was being deallocated before I was sending the IBAction to it. This explains the variable error messages, because sending a message to a deallocated object can point to anything. The problem was fixed by declaring a property (as retain) for the TestController instance, controller.

Use property leftItemsSupplementBackButton of UINavigationItem Class

In my app I want to show a button item together the back button in the navigation bar. I read the doc of the UINavigationItem class and I found the property leftItemsSupplementBackButton that seems to be just for me. Then I used this line of code:
- (void)viewDidLoad{
[super viewDidLoad];
[self.navigationItem setLeftItemsSupplementBackButton:YES];
}
But when I run the app I get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem setLeftItemsSupplementBackButton:]: unrecognized selector sent to instance 0x10faefb0'
and the 0x10faefb0 instance is:
_navigationItem UINavigationItem * 0x10faefb0
From the error seems that self.navigationItem doesn't have this property as is said in the apple class reference. Where i'm wrong?
That's for iOS 5 only. Are you running on iOS 4?