Navigation Controller .. Table view Background image - ios7

When I add a Navigation Controller, I have two views: A Navigation Controller and a Table View.
I want to add static cell in the Table view. The Table view class is UITableViewController. How can I add a background image to the Table View Controller?
I have no Class where I can write in the code. I am a Beginner in Xcode. Where can I add the code:
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"MyImage.png"]];
[tableView setBackgroundView:bg];
http://i.stack.imgur.com/zgJYk.png
or where there is an example?
thanks for your help

I don't think you can add a background image to a UITableViewControll from storyboard. What you have to do is create a custom class for your UITableViewControll and add the code in the ViewDidLoad method to add your background.
Create A Custom Class
dropbox.com/s/zqh5zu02f2dt0zo/create_custom_class.png
Assign your custom class to your Storyboard tableviewcontroller.
dropbox.com/s/5l94b9htfa1mz2w/add_custom_class.png
Add your code in the ViewDidLoad for your background image.
dropbox.com/s/2kz6m4iku27kyxz/code.png
Your app should now have a custom background behind the tableview.
dropbox.com/s/ks4riraqblaluoy/app.png
I hope that helps.

Related

How to set index of UIViewController as background

I'm trying to set background to the entire app from the code:
UIViewController *controller = [[UIViewController alloc] init];
controller.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background#2x.png"]];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
In the Storyboard I have a simple button in the main UIViewController. In the AppDelegate.m I set that code above, but, I background has added, they is in front of the text that is in the Storyboard.
I want to know how can I set that background from the current index to the last index in the stage.
You can create a subview, set the background image in that subview, frame it to the right size and then send that subview to a position "behind" everything else:
[mainView addSubview:backG1];
[mainView sendSubviewToBack:backG1];
Well, wenn you use a storyboard at all, AND declare it in your project settings as THE storyboard of your app, then you are not supposed to create and set the root view controller in your app delegate.
Both of them is perfectly fine, but one is the interface builder/storyboard option and the other is the programmatical way. Both ways just don't agree!!!
If you want to go for storyboards, which I encourage you to do, then give your root view controller an ID and in aoru ypp delegate method didFinishLoadingWithOptions: fetch it from the storyboard and set its background view then.
Have in mind: When you use a background view then you need to set all the background colours of all your view items (that may be tables, table cells, cell content views etc. pp.) to clearColor.
When you set an initial view controller in code (in AppDelegate.m, under didFinishLaunchingWithOptions), then it overrides the root view controller in your storyboard.
You can either set your view controller's background in the storyboard, or initialise it like you did - but then you need to create all other UI elements in code as well.

usings static buttons to access different view controllers views

As the titles states I am looking to have a main view controller with a few buttons. Depending on which button was pressed I would like to load a view of a separate view controller in a contained field below the buttons where I can still access the buttons and the content in the view. How should I attempt to accomplish this?
All you have to do is add the viewcontroller's view as you would any other view. So it would look something like;
ViewController *vc = [[ViewController alloc] init...];
[vc.view setFrame:whatever frame you want];
[self.view addSubview:vc];
And just have that called in your button's action method.
This sounds like a job for a UITabBarController

Static UITableView not fullscreen

For my registration form, I am currently using a UITableView which isn't fullscreen and I add cells programmatically through hardcoding the datasource methods. By the time the whole class got very complex and huge.
Pastebin link
The cells are custom and have a UILabel and a UITextfield. Now one of the cells should have a button instead of the textfield. This would make the whole thing more complex then it should be, in my opinion. So my thought was using the static feature of the tableview in the storyboard. But this requiers a UITableViewController, if I use one the TableView is always fullscreen. Is there a way to se the static feature without a fullscreen TableView??
If you have a fixed number of cells, the static table view controller is a good option. Instead of implementing the datasource methods, as you mentioned, you can include each input field as an IB outlet.
If you want a static table view controller that is not full-width, embed the table view controller inside a container view.
For example, create a new view controller, add a container view object w/ the desired width in this new view controller, and then connect your static table view controller to the container view.
Note that the static table view controller becomes a childViewController of the enclosing view controller. You can facilitate access to the textFields from the enclosing view controller w/ a weak property to the textFields w/in the child view controller.
- (UITextField *)surnameTextField
{
UITextField *textField;
// reference childController that is initiated via containerView
if ([[self.childViewControllers lastObject] isKindOfClass:[NameViewController class]])
{
NameViewController *nameVC = [self.childViewControllers lastObject];
textField = nameVC.surnameTextField;
}
return textField;
}
You do not need to use a UITableViewController. Just drag and drop a table view from the control palette onto a UIViewController in your storyboard. Size and position it how you want to and add any other controls to the UIViewController that you need.
In the property sheet for the UITableView set the content type to 'Static Cells' then define your cells how you want them.

UIImageView - class never called

I'm using StoryBoard to create my app.
I created a custom class of UIImageView. In StoryBoard I added a UIImageView in my view and linked it to my custom class.
My class is never called and my imageview is not displayed. Did i miss something? Thanks.

Customizing Custom UIView class

I have a custom UIView class that creates a view I can use in my main view controller that allows for better dragging. The problem, is that right now, the object I'm dragging is just a black box. I would like to be able to put my own custom image into that box. How would I do this? The custom UIView only has a .h and a .m and I don't know which method to put the code in.
Here's the code Im using right now
UIImageView *player = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 37, 37)];
player.image = [UIImage imageNamed:#"ghost.png"];
[self addSubview: player];
You could
Add your custom view in your view controllers main xib file and add the image view to it in the interface builder view
In your view controllers viewDidLoad method you could add the UIImageView to the custom view using your current code
Override the drawRect method of your custom view and draw the image there see here (however note the answer which says you should not load the image in the drawRect method, load the image on construction of your view in the initWithFrame or the awakeFromNib method depending on how you load it)