How to change UITabbarController's More ViewControllers UITableViewCells images? - ios

More viewcontroller images are showing up in default blue background instead on original images. I want to change them to original images and also want to increase UITableViewCell's height.
I have tried implementing tableview delegate methods on UITabbarController, but nothing working out.
Even moreNavigationController is also not changing.
1) Where do i have to write these custom methods viewDidLoad or viewWillAppear. Also shouldSelectViewController is not getting called. First time when i select a tabbar item it is being called and when i select the more item it is not getting called.
2) Where should i implement UITableView delegate methods.
My screen -
required screen -
A solution using swift is helpful. Thanks in advance.

I got the requirement working. The step wise procedure I followed is
Take a ViewController which extends UITabbarController.
Take an array with five elements exactly.(If more than five then default More functionality gets enabled).
First four tabs as required and fifth should be 'More' tab. With required tab images.
For 'More' tab create a View Controller which extends UITableView delegates and datasources. And implement respective methods of delegate and datasources.
Take an array of the Cells you want to display and display them.
Link this 'More' View Controller to the 'More' tab.
Change the images in tableview in cellForRowAtIndexPath method.
Run the application and check by selecting 'More' tab. This time it should show the changed UI.
When each cell should show different View Controllers on selecting the cells, then segue to different view controllers using the segues from ViewController (Not segue from the tablecell). Define a unique segue id for each segue and show the viewcontrollers based on switch or ifelse conditions in shouldSelectViewController using performSegueWithIdentifier.
Thanks #KKRocks for the valuable links.

There's some content to be unpacked here. I am not entirely certain I fully understand the question but I'll go ahead and reply partially as best I can.
ViewDidLoad and ViewWillAppear
You add code in viewDidLoad for initialization. This method will run when your view is originally loaded and unless you're instantiating the controller every time it will only run once ( in this case you dont because you're using the prebuilt tabbar system which takes care of that for you)
So I would add the styling code in viewDidLoad()
When a viewController is to be displayed, viewWillAppear() will be called. This will happen every time so if you need to perform repetitive tasks like network calls, restyling based on some other data, refreshing your tables, you should do it here.
Table methods
For doing whatever you need to do with a table you will most likely need both UITableViewDelegate and UITableViewDataSource to your view controller. Look up any UITableView tutorial online they're many very comprehensive and will explain how to add all the table methods you need in your viewController.

Related

Passing through Segues, Determining what view the user is on and NavigationController buttons not appearing

Sorry for the long and possibly confusing question. In this I have 2 main problems with my code, those being: 1- When I embed my viewControllers in a UINavigationController and add a bar button item, nothing appears, yet it appears when I add it to the pageViewController. Secondly, I am wondering if there is a way to do this differently and use one button on the pageView (which appears on all viewcontrollers in it) and just determine what the user was looking at when they pressed the button and are taken to another viewcontroller.
I am trying to build a page-based application, and I have set up the application with 7 view controllers (One for each day of the week). I then have an AddViewController, where users can add data to a certain day. I was wondering if there is a way to only use 1 addView linked to the NavBar on the PageViewController, as when I embed all other viewControllers and add a bar button, it does not show up.
With the pageViewController being embedded, this is what it looks like with a bar button on it.
This then leads to:
Which works well, however I am wanting to pass data to various arrays (one for each viewController), and I want to know which ViewController the user wishes to add to (based off what day they were on). Is there a way to determine this and then unwind to the viewController and append the right data to the right array or should I have one addView per dayViewController? If that is the case, I am coming across the issue whereby the bar button items do not appear on the viewControllers when they are embedded in a navigationController. It looks like this:
StoryBoard: (Example: MondayViewController)
The outcome is a missing barButton: (Keep in mind I changed the tint Colour to white so it would be visible)
I was wondering if anyone has the answer to either of my problems, and once again, thanks for taking the time to look at this array of questions in one problem.
Any suggestions are welcome !
Rowan,
You can do this:
Create an UINavigationViewController and then embed an UIPageViewController in it.
In the data source for the UIPageViewController implement these two methods:
- pageViewController:viewControllerBeforeViewController:
- pageViewController:viewControllerAfterViewController:
Here you will return the correct instance of your DayViewController for each position (or nil if you are on the first/last page). Your data model would also be set here.
Add your "Add" bar button to the navigation bar of the UIPageViewController and let it push your AddViewController. When pushing the AddViewController provide to it the info on which day is currently visible. You will probably need to keep track of this your self. Use the - pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted: method of the UIPageViewController delegate.

iOS: show segue prevents UITableViewController to auto scroll when UITextField gets focus

I have a UITableViewController that is presented via a show (push) segue. Its rows have UITextFields. On the iPhone, when a textfield get focus, the keyboard hides the textfield if said textfield is towards the bottom of the screen.
This only happens on the iPhone, with any segue except "present modally" or "present as popover" ones. For these latter segues, the table scrolls up the textfield so that it's not covered by the keyboard - the standard behavior for UITableViewController.
On the iPad it works as expected (auto-scrolling the table), regardless of the segue type. Any idea why?
I've created a new project just to test this, it works as expected. In the initial project where it doesn't work, the UITableViewController is a secondary controller of a SplitViewController.
I've tested with or without auto-layout, same results.
iOS8
Thanks
The first screenshot shows the table with no textfield having focus
The second one was taken after the last textfield got focus. It is covered by the keyboard.
PS: I've tried the same with just a UITableViewController, not a subclass of UITableViewController as initially. I know in subclasses there is a problem if for example you override viewWillAppear but do not call super. This is not the case.
Relevant Apple documentation excerpt:
Note: A table view controller supports inline editing of table view rows; if, for example, rows have embedded text fields in editing mode, it scrolls the row being edited above the virtual keyboard that is displayed. It also supports the NSFetchedResultsController class for managing the results returned from a Core Data fetch request.
The UITableViewController class implements the foregoing behavior by overriding loadView, viewWillAppear:, and other methods inherited from UIViewController. In your subclass of UITableViewController, you may also override these methods to acquire specialized behavior. If you do override these methods, be sure to invoke the superclass implementation of the method, usually as the first method call, to get the default behavior.
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewAndDataModel/TableViewAndDataModel.html#//apple_ref/doc/uid/TP40007451-CH5-SW7
I have checked the behaviour and faced this kind of issue in iPhone 6.
In viewDidLoad method -
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
I wish I could tell you why the code below works, but I can't; I am aware that makes this a bad answer. With that said, it does work consistently across my application.
Add a simple completion block to your view controller dismissal. In my code, that means the viewWillAppear is called twice, once before dismissal and once after (as I said, I don't know why this works but it does for me).
dismissViewControllerAnimated(true) { self.viewWillAppear(true) }

Uipageview with separate lists

I am writing an app in xCode 6.2 using storyboards and there is a need to present 2 different lists within a page view type setup (similar to Beat - Music Player).
The PageView controller is something I have never used before, so, I have looked at several examples and all deal with an Image View and changing the content of that based on an array. Whereas, what I am essentially trying to achieve is two separate ViewControllers being swiped between using the PageView controller. Is this even possible? If so, would anybody be able to point me in the right direction please?
the magic does by the two delegate methods viewControllerBeforeViewController and viewControllerAfterViewController ...
when you load the first viewcontroller to your pageviewcontroller with setViewControllers:#[theFirstViewController] the pageviewcontroller will ask the two delegates for the next and the previous vcs... you are responsible that the delegates returns the vcs you want to display, no matter what kind of vc you want to display...

Implementing A Mail app-like User Interface

I am trying to implement a user interface that is similar to the iPhone's Mail app.
The main screen displays a table. From the table the user can select a cell, at which point the next screen is launched. At the bottom, there is a bar showing a short text and an icon.
The second screen displays the details of the cell. It will also be a table display. The bottom bar shows icons associated to this screen.
What kind of layouts do I use to implement this in Xcode?
1. Do I use a View controller, add a View and embed a TableView and a Toolbar inside that view?
2. Do I use a Table View Controller and add a Table View inside it and use the bottom tool bar that comes with the table view?
In the Table View Programming Guide for iOS, under 'Recommendations for Creating and Configuring Table Views,' it says 'Use an instance of a subclass of UITableViewController to create and manage a table view.' When I use this, the bottom bar can only be fixed or disappear when going back and forth between two screens via segue. That makes me wonder whether I should just use a View controller which is against the recommendation.
Use a UIViewController
Why?
If you are going to display more than a tableView then it is recommended to use a UIViewController for the storyboard.
UIViewController are much more flexible. I guess your confusion comes from the following documentation line:
Use an instance of a subclass of UITableViewController to create and
manage a table view
This does not mean you must to drag and drop a UITableViewController on the storyboard. It means your class need to inherit from UITableViewController or at least implement the deleguate and datasource methods.
You would use UITableViewController only and only if you need to display a tableView.

How can I add more than one UITableView in a UIViewController?

Here is my app.
http://www.flickr.com/photos/baozhiqiang/6943921630/
http://www.flickr.com/photos/baozhiqiang/6943921900/
You can see three buttons at the top of the main screen. When you click it, the gallery will change to next. They are not the same layout style.
I created it by making three ScrollView in a big ScrollView. Code like this:
[backgroundScrollView addSubview:innerNewsScrollView];
[backgroundScrollView addSubview:innerHotScrollView];
[backgroundScrollView addSubview:innerLinkScrollView];
And when click the button, I changed the frame of the ScrollView.
Now there is a problem, when I add more than 100 Pictures(UIButton with image) to the ScrollView, It had crashed. I want to use UITableView replace ScrollView. But how can I Control more than one UITableView in a UIViewController?
Anybody can help me!
Two possibilities:
All the table view delegate methods include the table in question as one of the paramters, so it would simply be a case of checking which table is requesting data/information
You don't have to point your table views to the view controller. Your view controller could store two objects whose only purpose is to repond to table view delegate methods
Unless the tables are trivial, I think the second option is the cleanest.
Add all of your UITableViews in the UIViewController's view, set their tag properties to something you can distinct them and also set their delegates (usually self if your UIViewController implements the UITableViewDelegate protocol). Every method in the UITableViewDelegate passes UITableView reference as an argument and with the value of the tag property you can find out which table view is processed.

Resources