Is there anything like a GLKTableViewController? - ios

I am currently using a GLKView connected to a GLKViewController in my iOS project to animate the background of my app which works fine. Now I introduced a UITableViewController for displaying some list. I also would like to animate the table view's background similar to the other view controllers. But therefore I need something like a GLKTableViewController, but this doesn't exist.
Somebody any ideas ?

Finally I did implement the most important UITableViewController functionalities myself. Basically it's very simple, just implement the following two protocols/interfaces:
UITableViewDelegate
UITableViewDataSource
... with their corresponding implementations in the *.m file.
Hope this helps also other people. Regards.

Related

How to apply style to all UIViews programatically

I have a class that defines all styles on a UIVIew.
They are all predefined but I'm not sure when to fire this.
When I try to create an extension for this:
extension UIView
{
func willMoveToSuperview(newSuperview: UIView?)
{
self.stylize() // Another extension somewhere (not here my problem)
}
}
And I'm getting this error:
Method 'willMoveToSuperview' with Objective-C selector conflicts with
previews declaration with the same Objective-c selector
I have tried to override it, but didn't worked either.
Any ideas on how to be able to apply a same behaviour when all of my UIViews will become visible?
You can use Swizzling technic to customize UIView's function. Take a look at:
http://nshipster.com/method-swizzling/ (objective-c)
or
http://nshipster.com/swift-objc-runtime/ (swift)
Hope that helps.
Even though Swift's Extensions are similar to Categories from Objective-C, what you are trying to do is not allowed in Swift.
You cannot override existing functionality:
Extensions can add new functionality to a type, but they cannot override existing functionality.
Source: Swift Extensions - Apple Documentation
Depending on what it is that you are trying to style, you might want to take a look at UIAppearance, it will allow you to style default colors for the UINavigationBar, amongst other things. NSHipster has a good post about it: NSHipster - UIAppearance
You can create a subclass of UIView with the method .stylize().
Then each view you create, you inherit of you UIView subclass.
You'll be able to cal .stylize() on each UIViewSubclass. Simply write the style code inside the subclass and inherite.
Or
Use a category to add the method to the existing UIView class.
See : https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html
Outside of swizzling (not generally recommended), or subclassing as noted by David in his answer, there isn't really a way to override existing methods on a class and its subclasses.
One thing you might try is creating a base class for your view controller instead of all your views. In your view controller base class, you could override viewWillLayoutSubviews to recurse through the view hierarchy and call stylize on each view. This means you would be using the subclass approach in fewer places (just view controllers as opposed to all views).
Another thing you might consider if taking the subclassing approach with UIView is that if you are subclassing anyway, you can take advantage of things like #IBDesignable and #IBInspectable to better integrate those UIView subclasses with storyboards and live preview.
I wrote a Swift library which does exactly this, and it works well for the type of styling it seems you want to do: https://github.com/daniel-hall/Stylish

Design iOS View in Code without storyboard

I want to design and generate view elements in code, without using storyboard. But I haven't figure out a simple way to locate where should I put my view elements by describing its CGRect. For example, I can drag a button direct into the storyboard and put it where i want, however, in code, I have to write something like
[button setFrame:CGRectMake(24.0f, 113.0f, 271.0f, 140.0f)];
Is there any way or any software can help me?
Your question is a bit broad. You can create your view in code by including in your subclass of UIViewController properties for each subview (control) element and then make all the initialisation in designated initialiser and setting frames and other customisation in viewDidLoad method most likely. But for details where to what set you should go to references for UIViewController lifecycle as it may depend on what you want to achieve. in some cases setting frames in viewDidLoad will be fine whereas sometimes you will need to make some changes in viewDidLayoutSubviews for example.

xcode 4 drawing rectangles

i'm very new to xcode. i've googled this and even serched here and i didn't find exactly what i was looking for. i really wanna get this. especially since it's the most basic thing there is.
so, i have the .h and .m files
i want to DRAG a uiview into the .xib file, i don't want it to be as big as the screen, so i resize it.
now i want to draw a bunch of rectangles INSIDE this view object.
how do i go about doing this?
your help would be greatly appreciated!
So you add a generic UIView then create a subclass of UIView and do your drawing inside the drawRect method.
Then change the class of the UIView to your subclass name in the inspector.
Be sure to #include your header in the app delegate.
That's the basic thing.
For more sophistication, you're going to want to learn to use UIViewController subclasses as well. These are used all over ios.

Implementing AdMob with lots of View Controllers

I'm sorry for this newbie question but here it goes. I'm just starting with iOS and implementing AdMob in my app. The app is running fine with the Ads working but I have four View Controllers and for the sake of test I just implement all theses methods in all View Controllers.
- (GADRequest *)createRequest
- (void)adViewDidReceiveAd:(GADBannerView *)adView
- (void)adView:(GADBannerView *)view
But imagine if I had 100 VC...There's a way to do it only in one file and import like a .h file? Yes, my OOP knowledge is limited and If somebody can help me I would appreciate.
Thanks
There is a tutorial on implementing a singleton for ads, but you'd still need to implement the listener methods (if you want them) for each View Controller because you may need to react differently in different situations.
Personally, I think it's cleaner to just have those methods in each of your VC that have ads, and reconsider which VCs need ads in them. Your title screen and options screen aren't great candidates - a best practice is to only put ads in VCs where your users will spend most of their time.
Just read your question and since it hasn't been answered yet, I would like to share my solution.
Create a ViewController that would act as base view controller for the rest of VCs. Implement the functions and listeners for ads in that base view controller and extend (inherit) rest of the VCs from this baseVC. Do all the work in the baseVC functions and if you need to add something different in a specific VC, you can do that and then call super of that function.
Hope this helps.

UIView Responsabilities (Object-Oriented Programming)

I am just starting out with iOS app development and it's been a great experience so far. Apple documentation is great, but there are some questions I have that are not as technical and only someone with experience might be able to answer.
I have a bunch of UIViewController which handle the "dynamic skinning" of the custom UIViews that they control. This leads to a controller with big chunks of code which seems a bit unpractical to me.
So the question is: Following the MVC pattern, should I give the responsibility of setting a UIFont, UIColor, etc to the view itself? Or should I create "micro" controllers that handle this task using some kind of input?
Thanks for the response.
Creating UIView subclasses that handle the layout works. Override layoutSubviews in the UIView subclass to do the positioning layout (setting frames etc). I find the init method to be a good place to set fonts, colors etc.
Now the UIViewController has relatively little code related to the custom UIView. The viewController just needs to position an instance of the custom UIView and perhaps set a few properties (like a textLabel's text).

Resources