Relative Height of UITableview - iphone

In RootViewController am using a UITableView for displaying the content of data. In the didSelectRowAtIndexPath method, I am calling another view controller (DetailViewController) to display detailed data. For displaying this detailed data I am using a UITableview in the DetailViewController also. This table contains one section and only one row.
Now the problem is that I have to adjust the table's height dynamically when I move from RootViewController to DetailViewController. How can I make the height of the UITableView dynamic between the two classes?
Any help would be Appreciated!

You can implement the UITableViewDelegate method something like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [TextToDisplay sizeWithFont:/*DESIRED_FONT*/ constrainedToSize:/*YOUR DESIRED_SIZE*/ lineBreakMode:/*DESIRED_LINEBREAKMODE*/].height;
}
to get variable heights.

It sounds like your trying to reuse a UITableView between two different UIViewControllers. I think your better off having the RootViewController have it's own UITableView which is set to a dynamic height and width using the UIView autoresizingMask property. Then when you select a row and push on the DetailViewController in a UINavigationController stack it would have it'd own UITableView to display the detail information your trying to show.
This interaction technique is used throughout other iPhone applications like Mail. If I misunderstood your question please let me know.

Related

How to add a UIView above a UITableView in iOS?

I am using the xcode template to create a UITableView application with UINavigationController.
I need to add a UIView (at fixed position) between the UINavigationBar and the UITableView. How to do that ?
Thanks.
You can do this by setting the UITableView's tableHeaderView property.
UITableView class reference
tableHeaderView
Returns an accessory view that is displayed above the table.
#property(nonatomic, retain) UIView *tableHeaderView
Discussion The default value is nil. The table header view is
different from a section header.
Availability Available in iOS 2.0 and later.
Add UIView and UITableView as subviews of UIView and then position their height, width and x, y position from the Size Inspector in Interface builder or Use CGRectMake in objective-c
you need to implement following UITableview delegate methods
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Step 1)
Create a header view as, set outlet to that view.
#property(nonatomic,strong)IBOutlet UIView *viewHeader;
Setp 2)
Add following single line code on viewDidLoad
[self.tableview setTableHeaderView:self.viewHeader];
Done!!!
Views are maintained in a hierarchy in iOS. They are maintained essentially as an array with the latest view first. To insert some view below one view or above another you just need to manipulate this.
All this is theory, I have not done what you want. So dont hold a grudge against me ;) this is a friendly suggestion.
[self.view insertSubview:yourNewView belowSubview:navigationController];

Insert ScrollView in TableView?

I have a TableView with one cell and I want to insert in this cell a lot of text so I think I'll need to use a ScrollView for scroll the text.
How can I insert? Is correct this method?
This is a help in the application, is correct use this modality?
Sorry but I'm a beginner and I don't have an iPhone or iPod, thanks!
While I concur with 7KV7's original comment, it doesn't look like there is need of a tableview in this scenario...
Just in case someone else happens upon this looking for an answer to the "Scrollview in a Tableview" question here are few clarifying points for the above comments.
The technical problem with having a tableview and a scrollview together on the same view is that UITableView is already a descendent of UIScrollView and if you attempt to handle both in the same view then you will end up with quite a mess with conflicting delegate messages.
As suggested by iPhonePgr, you can create a custom UITableViewCell. The first thought would be to let the UITableViewCell act as the delegate for it's own scroll view. The problem here is that the cell and it's contents could be discarded or reused at any moment as part of tableview's dequeue functionality.
So some ground rules to guide your implementation:
Whatever your solution, you're probably going to end up making a custom controller class, possibly derived from NSObject and implementing UIScrollViewDelegate.
The custom controller object acts as the mediator between the model object and the cell.
You will probably have an array or array-of-arrays that mirrors the model hierarchy driving the UITableView structure.
Because the cells can be discarded at any time you will have restore the scroll view state on cell initialization and preserve the state has part of handling your delegate actions or through a custom UITableViewCell implementing prepareForReuse.
Hopefully these points will come in useful to anyone who runs across this entry.
You need to create a custom cell by inheriting UITableViewCell and then add UIScrollView in the customcell. Then Use that cell in the Table view.
you can put your text in UITextView and add it as a subview in your UITableViewCell,because
UITextView is inherited from UIScrollView,
No need to add UIScrollView if you use UITextView
When you create UITableView you implement a number of delegate method which you can see by pressing the window key and then double clicking the UITableView delegate . In one of the methods you can set the cell height as per your requirement. By doing this your cell height can vary.
- (CGFloat)tableView:(UITableView *)resultTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 150;
}
As your table has a defined height, when the text in cell will be too much to contain into a scrollview will be automatically inserted.

How to place two buttons on top of tableview

i have been looking, but can't find my answer.
my question is how to make a tableview with two buttons above it.
here is a pic of something i would like to do.
I have the grouped tableview, but can't figure out how to make it look like the image.
thanks for the help
http://img137.imageshack.us/i/imagezjb.png/
Create a view with your two buttons as subviews, then set the tableHeaderView property on your table view to be that view.
#LucasTizma's answer is valid but you can also return views for header sections by implementing the method below, which returns a UIView. In this case, you will be able to return different views for different header sections so if for instance you had a header for Games and a header for Utilities on the same tableView, you could return different images/buttons for each header (i.e. a special game promo in the game section and a different one for Utilities).
Basically the process is the same: you create a UIView, add the buttons/images as subviews and then return it on the method.
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
Cheers,
Rog

adding textfield,label above the uitableview

How to design a tableview similar contact application in iphone.........
you want the delegate method:
- (UIView)tableView:(UITableView *)tableView viewForHeaderAtSection:(NSInteger)section;
construct and return a UIView in that method.
Most likely they use UITableView with grouped style and custom views for table header and footer. (see tableFooterView and tableHeaderView properties)

Look like iPhone inbuilt contact applications image selection

I have created an application in which i have to add users to the sqlite database.
Now the problem is I want the look of the standard iPhone Contact application Where while adding user we have the width of first cell smaller than other cells and the image before that cell..
Can you please give me the idea how such thing is possible.
How to make one cell small and rest others of normal size..
Thanks for any help in advance
There are three UITableViewDelegate messages you can listen for to adjust height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
However, even thought I didn't write Contacts.app I have a feeling they are also using
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
To adjust the views as well. Remember, you don't have to pack everything into a single monolithic custom table view cell. You can create multiple custom table view cells and load them each appropriately depending on the index path.
The contact detail view is a grouped tableview. Each cluster of cells is a section. The top section is a single custom cell with two subviews that look like squashed tableview cells. The left view shows the contact's photo. The right view shows the name.
To reproduce, create a custom UITableView subclass and lay it out like you want either programmatically or in Interface Builder. Then in the tableview delegate's cellForRowAtIndexPath check indexPath.section and return the proper row for the section.
It appears that the Contacts app uses a custom tableHeaderView when presenting the contact details with an image and label. A similar implementation is included in the sample project iPhoneCoreDataRecipes. The RecipeDetailView loads a separate nib in tableViewHeaderView that is used to set the tableView.tableHeaderView property. Have a look at RecipeDetailViewController.{h,m} and DetailHeaderView.xib. When the Contacts app switches to editing mode, the headerView appears to be swapped out for another view that has a button and a tableView with a single cell. This will allow you to set up a separate tableViewDelegate to handle the Name parts of the contact and a delegate to handle the address / telephony details.