iphone uitabviewcontroller - iphone

I want to have same segmented control across on all navigation tabs with segment value change delegate in it which refereshes currently selected tab data. . I dont want to create different sengemented control for each tab.
Please guide me. Thanks in advance.
Regards,
Malleswar

You would need to make your UISegmentedControl a peer of the UITabBarController view. So it would look like this:
-------------------
|UISegmentedControl |
|-------------------|
| |
| |
| |
| |
| |
|UITabBarController |
| |
| |
| |
| |
| |
-------------------
The key here is that your UISegmentedControl needs to not be a subview of the UITabBarController view, so I would create a separate UIViewController subclass that owns and lays out the UISegmentedControl and UITabBarController views.
Also, I'd recommend embedding the UISegmentedControl in a UIToolBar. That will look a lot better than placing it on a blank view.

Related

Loading a UIScrollView like a UiTableView

Is there a way to load a UIScrollView in a similar way to how a UITableView is loaded - in other words, only load the visible 'cells'?
For my example I have a large scroll view which can be scrolled in any direction. Inside that are 'cells' which I add to the scroll view using code. The cells consist of data gathered from json feeds (one feed per cell). I would like to only load the feeds for the visible cells, and then cache the ones already loaded, so they don't need to be reloaded.
Is there a good method of doing this? Or is there another direction I should be taking to get this result?
A couple of answers have suggested a tiling approach, but I'm not sure that tiling is quite the right approach, since the whole cell needs to be loaded when part of it is visible. Another approach which google hints at is putting a UITableView within a UIScrollView, but I've yet to try this.
——————————----------------------
| | | < a 'cell' row in the scrollview
| - - - -| - - - - - - - - - - |
screen > | | |
| | |
—————————— |
| | < whole of scrollable area
| |
| |
| |
--------------------------------
You are describing "tiling."
Take a look at Apple's sample code - it demonstrates an approach to tiling.
You can use CATiledLayer.
https://stackoverflow.com/questions/tagged/catiledlayer
https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CATiledLayer_class/Introduction/Introduction.html

steps for creating UIScrollView with Interface Builder

I'm in the midst of trying to use a UIScrollView and there appears to be some fundamental thing that I'm just not understanding.
Let's say I want to use a UIScrollView in my iphone app. I have a View filled with buttons that is 320x700. Obviously, this is too big for the iPhone which is 320x480. So I know I have to use a UIScrollView. However, is this the order that I should be creating the objects
Create a UIScrollView that is 320x700 as the dimensions in "View"
Place all my buttons, etc, on this scroll view
In the viewDidLoad set the contentSize to 320x700
Set the delegate of the UIScrollView to the File Owner, and the view of the FileOwner to the UIScrollView
Reset the size of the View back to 320x480.
Is this right?
This works, but it doesn't make sense to me. I get that the View is supposed to be the canvas, where I add all the UI elements. I want the "canvas" of the iPhone app to be 320x700, and I want to be able to put my buttons, etc on this 320x700 canvas. But if I don't change the size of the UIScrollView back to 320x480, it won't scroll, because I need to set the content size of the UIScrollView larger than its size.
But if I set the size of the UIScrollView to 320x480, then I don't see the screen and the buttons between 480 and 700 in Interface Builder! So it seems like I'm supposed to make all my edits and add all my UI elements to the UIScrollView, and then set it back to the 320x480!
Is there some other way to do this that makes more sense? What am I missing in my understanding of how this should work?
UPDATE
I have posted another solution here which I think is simpler and better.
ORIGINAL
Here's another way to do this that you might like better:
Set the File's Owner placeholder's custom class to your view controller subclass.
Create the UIScrollView as a top-level object in your nib. Set its size to the screen size (320x460) or just turn on a status bar under "Simulated Metrics".
Connect the scroll view's delegate outlet to File's Owner.
Set the File's Owner's view outlet to the scroll view.
Create a UIView as another top-level object in your nib. This will be your content view.
Set the content view's size to 320x700.
Create a strong (or retain, if not using ARC) outlet named contentView in your view controller (File's Owner) and connect it to the content view.
Put your buttons in the content view.
In your view controller's viewDidLoad, do this:
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.contentView];
((UIScrollView *)self.view).contentSize = self.contentView.frame.size;
}
In your view controller's viewDidUnload, do this:
- (void)viewDidUnload {
self.contentView = nil;
[super viewDidUnload];
}
Full size
You are right, the View is the canvas where you add all the UI elements.
Interface builder is kind of weird at first but you will get used to it, that is just the way it works.
You are getting stuck on the fact that you have to resize the ScrollView. You should think of it like this:
The ScrollView has a frame size and a content size. The way it's built is that if the content size is larger than the frame size then it will scroll. You have to make the frame as big as you need to in the interface builder so you can position the elements that go inside. When you run the application you should resize the frame of the scroll to fit inside the iPhone's screen resolution. It doesn't make sense for your controls to have a frame bigger than the screen.
--------------------------------------------
| | | |
| | | |
| | | |
| | | |
| | |<------------------ iPhone Screen frame
| | | |
| | | |
| | | |
| | | |<------- ScrollView Content size
| | | |
| | | |
| | |<----------------- ScrollView Frame Size
| | | |
| | | |
| | | |
| | | |
| | | |
| ------------------------ |
| |
| |
| |
--------------------------------------------
I hope this representation will make it clearer how things should suppose to work.To put it some other way, the scroll frame is the hole trough you can see the content, if the whole is as big as the content then you have no need to scroll cos you can see it all.
I would suggest also trying to write the components in code without using IB to get a better understanding.

Table View inside of View Controller

All,
I have a regular view controller with several buttons on it, but when one of the buttons is pressed it retrieves information that I want to throw right above the buttons.
For the sake of this, imagine a blank view controller with one button at the bottom. When this button is called, it gets X number of items that need to be listed (and available for selection) right above the button.
I tried illustrating it for you here. :X lol. There are three items viewed, but say that 10 items came back - I need to be able to scroll through the list as well.
The question is this: how do I add a scrolling view (possibly table view) inside of my view controller so that this works as explained?
__________________
| |
| |
| item 1 |
| |
| item 2 |
| |
| item 3 |
| |
| |
| (button) |
| |
|________________|
Thanks
You simply add the UITableView as a subview of the view controller and implement the UITableViewDataSource and UITableViewDelegate protocols as usual.
It's not harder than that. Try it and if you get any problems ask another question.
Do you have Scrolling Enabled on Table View ?
I don't think so you need to do anything. TableView will take care of it.

Embedding a long UIWebView within a table view cell with various heights

I want to be able to embed a UIWebView into a tableview's cell (grouped style).
The web view is long (longer than the screen), and I want it to display it's full length. So there is no scrolling within the web view itself, just on the table.
------------------------
| a normal table cell |
------------------------
| a normal table cell 2|
------------------------
| a long webview |
| which doesn't scroll|
| within itself |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
------------------------
The web view will have various heights so how can I discover the the height of the webview in order to adjust the height in heightForRowAtIndexPath?
Here's how you could do it, but see my caution below:
You could load the web view, then use a javascript function to determine the height of the content. You could then use [myWebView stringByEvaluatingJavaScriptFromString: ..] to get the height.
Here's the problem. UIWebViews are fairly slow. The table can't present itself until it knows the heights of the rows, because that's how it determines which table cells to fetch. So scrolling your table view will be jerky, because every time you scroll down to a new cell, the height will need to be computed.
There are two approaches you can take:
1) Don't use a UIWebView embedded in a UITableCell. Instead use a UILabel and determine its height using some of the NSString convenience methods for doing this.
2) Use a UIWebView for the entire table. You can very closely simulate a tableview by doing this, and you will get the UI you need. To handle things like clicks, use the URL loading hooks provided by UIWebViewDelegate.

Create a Split View ViewController

Fairly new to iPhone/Cocoa development, so I'm having difficulty adjusting.
I want to create a ViewController that has two separate subViews. Kind of how the TabViewController/NavigationController is set up, but I want to be able to control what's in the other portion as well (not to mention sizing, etc.). Either orientation is fine (top/bottom) or (left/right).
+--------+ +----+----+
| top | | l | r |
| | | e | i |
+--------+ | f | g |
| | | t | h |
| bottom | | | t |
+--------+ +----+----+
You can create a subclass of ViewController and add three properties:
FirstView, SecondView, isVertical
These three properties will in general be enough to create a simple split view. The consumer would be responsible for setting up those properties, and inside of your ViewController's loadView method, you would add both of those views to a new view, which you would then assign to the "view" property of the UIViewController.
That's really all there is to it for a extremely limited feature set Split ViewController. The rest of the features would mostly likely just customize how the views are sized and positioned.
Hope this helps, and please open source it :)