I have checked recent header files for PSListController , PSViewController and PSBaseView, but there is no method for acknowledgement of view creation, like iOS has viewDidLoad - Although there are many methods available for view Display. One I found is: -(id)initForContentSize:(CGSize)contentSize, but I don't want to use it as I don't think it would be appropriate to do so.
So which method should I choose in order to initialize my instance variables or do other stuff? Thanks.
Note: I am using rpetrich's Header Files.
Some of those headers are slightly older on the repository but looking at an iOS 7 version of PSViewController you will see that it is a subclass of UIViewController. UIViewController does contain viewDidLoad so PSListViewController "should" contain the same.
Source: http://www.developer.limneos.net/?framework=Preferences.framework&header=PSViewController.h
Related
I'm new to Xcode.I'm trying to figure out how to use showViewController.My question is how to call the UIViewController that to display ? via name or a identifier? And where can I find them ? In addition, the document says The default implementation of this method calls the targetViewControllerForAction:sender: method to locate an object in the view controller hierarchy that overrides this method,what does it mean? Should I call targetViewControllerForAction:sender:fist when using showViewController?
showViewController behavior basically depends on context you're app is in.
But calling it is really simple. All you need is reference to your UIViewController object(or it's subclass).
You can do it in couple of different ways:
If you're using Storyboards, give your storyboard view controller identifier, and use API call: UIStoryboard(name, bundle).instantiateViewControllerWithIdentifier(identifier). This gives you UIViewController that you should pass as an argument to showViewController. You could find information about API here: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIStoryboard_Class/index.html#//apple_ref/doc/uid/TP40010909-CH1-SW6
Also, you could get your UIVIewController instance directly constructing it using proper initializer.
So: not worry about this targetViewController method, just get your object (initialize it via constructor or get it from storyboard), and pass it to show method.
In case you have further questions - feel free to ask.
Here is the things.
I use a framework which contains only header files.
The framework use SOMEWebView which is a subclass of UIWebView.
I need to set this SOMEWebViews property "allowsInlineMediaPlayback" to "YES".
That webView is used by SOMEViewController's UIWebViewDelegate.
How can I make this?
Thanks in advance.
Create a category on SOMEWebView that has the following method declaration:
+ (BOOL)allowsInlineMediaPlayback
{
return YES;
}
EDIT:
N.B. Only do this when you control the code you're overriding. Doing this without knowing what you're doing can cause undesirable behaviour (especially when overriding Apple framework classes using this method). Since you're not in control of the code, I'd suggest you also check out "method swizzling" or see if you can simply subclass the SOMEWebView in question.
I am working on a view controller that has a long and unpretty view setup method.
For cleanliness, this view setup code is moved to a category, intended only for view setup.
This category references private selectors in the original view controller, and Xcode is showing warnings: Undeclared selector 'xyz:'
It seems to me I have these options, none of which seem good:
Leave the warnings, EYES CLOSED!
Expose private selectors publicly by declaring in header file
Declare a second category, which serves as a sub-category to my first category, in the original VC header file
I have gone with the last option, but I still have this feeling like I have to go poo or something. What is the optimal move here?
You can add a declaration to the private method in your category implementation
So in CustomViewController+ViewSetup.m
#interface CustomViewController (private)
// declare private methods and properties here which you know exist in CustomViewController.m
#end
In general though, I think that you are doing with the category is unnecessary. You can clean the code up in the original file and not need a category file to manage and maintain. Not to mention that if you change any of those private method signatures and forget to change it in the category, the compiler will not warn you and you will instead see a crash when you try to call one of those methods.
In my iOS application I have a 5 view controllers that all deal with the same feature (groups). These view controllers can be pushed on top of eachother in a few different configurations. I made a file called GroupViewHelper.h which uses #implementation to provide some functions for the groups feature. The functions look through the view controller stack and send a "refresh" message to a view controller of a specific type. The file looks like this:
#implementation UIViewController (GroupViewHelper)
- (void) refreshManageGroupsParent
{
// ...
}
- (void) refreshGroupDetailsParent
{
// ...
}
#end
My code works great and everything behaves as expected, but I get 14 warnings that are all very similar to this at build time:
ld: warning: instance method 'refreshGroupDetailsParent' in category from /Users/x/Library/Developer/Xcode/DerivedData/myapp-ayshzmsyeabbgqbbnbiixjhdmqgs/Build/Intermediates/myapp.build/Debug-iphonesimulator/myapp-dev.build/Objects-normal/i386/GroupMembersController.o conflicts with same method from another category
I think I'm getting this because I'm using a .H which is included in multiple places, but how do I correctly use #implementation in this situation?
I think I'm getting this because I'm using a .H which is included in multiple places
Well, sort of, but the real problem is that you've put the #implementation in the .h file in the first place. If you only included that .h file in one place, you would get away with it—but it would still not be the right way to do it.
but how do I correctly use #implementation in this situation?
Put it in a file called GroupViewHelper.m, and add that file to your project's sources, and put the #interface in GroupViewHelper.h.
Or, ideally, call them UIViewController+GroupViewHelper.m and UIViewController+GroupViewHelper.h, because that's the idiomatic way to name category files. (And if you use Xcode's "New File…" menu item to create a new Objective-C category file, that's what it will give you.)
In other words, interfaces and implementations for categories on existing classes work exactly the same as interfaces and implementations for new classes.
I have encountered exactly this issue. I had imported a reference to a header file, on a .m page. However, it also contained a reference to another header file, which contained a reference to another header file - that also referenced the conflicted header file. So indirectly the same header file was imported twice, causing the error.
In my case, the .m file did not need this reference. I was able to delete it, removing the error. My advice is check the files where you have included a reference to the offending header file, and verify that it actually is required.
Can Xcode 4.2 auto-generate me the stubs for the protocols i defined in the header-file?
In this tutorial (http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-and.html) in the note of point 4 the author says, Xcode will now auto generate the methods i need. Otherwise I did something wrong...
From your question, I can't understand exactly what you need.
If you need boilerplate code like the -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath implementation that comes when you subclass UITableViewController, then you should create your own templates as Grouchal suggests. Also check a similar question I asked here.
I think that the tutorial you link to refers to code sense, for example:
In a header file, add a protocol like <UITextFieldDelegate>:
#interface FirstViewController : UIViewController <UITextFieldDelegate>
Save, and then in your .m file, you can see the new methods that you can implement just by typing a dash "-" and then pressing "Escape" on your keyboard. It helps if you type the first letters, for example "-tex" and then "Escape" will display the methods of the UITextFieldDelegate.
Try the same with UITableViewDelegate and UITableViewDataSource, you will see that you'll get a similar result as the one at step 4 of your tutorial (note that in the screenshot, the user has already typed "-tab" to get the list of methods).
Check out Accessorizer if I'm not mistaken, it can do what you want.
Firstly you might want to look into using templates to achieve your goals:
http://blog.highorderbit.com/2009/03/15/customizing-xcode-cocoa-touch-file-templates/
The tutorial you have references also mentions in point 4:
Also note, if the method is not auto-generating you're probably doing
something wrong. That's the main way I know I'm doing something wrong,
or the program crashes.
This might indicate that you have not followed the previous steps 100%
If you create a new class through the Xcode wizard ( i.e. File->New->File or cmd-N and select Objective-C class ) then if you pick an appropriate built-in superclass from those in the 'Subclass Of' dropdown, you will get a template implementation with the essential stubs implemented, and commented-out versions of other methods, that you can base your code on. I've used this successfully for subclasses of UITableViewController. Not quite in the league of the Eclipse stub generation, but better than nothing.