I am developing an iphone app in which i have a segmented control that has details related to something like a book .
I want to show books menu tapping on books segment with uitableviewplain style .
but now I want another segment which should show the book vendor details with uitableviewgrouped .
how can i manage both these views with the segmented controller and mange the data source and delegate methods.
It seems that the simplest way to do that is to create two UITableViews for each purpose and show/hide them according to segmented control value.
In delegate and data source methods just check what tableview are you using, like:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == plainView){
}
if (tableView == groupView){
}
}
Related
I have to build a Course management app. I am using table views only for this app. Using the table view controllers.
The first view contains the semesters - 1,2,3,4....12.
The second view contains details that are respective to the previous table view controller.
The details in the second table view controller are: Lectures, Papers, To-do list, Record lecture.
Depending on the user's selection, he can access Lectures, Papers, List, Record Lecture for that particular semester.
I am not able to figure out how to pass data from the third view to the fourth and subsequent views. For eg. Lecture->Lecture 1: Introduction->Download PDF.
How do I assign a specific table view controller when the user taps a particular cell? using seques or cellForRowAtIndexPath method?
I am confused.
Kindly help me in this regard. Your help will be highly appreciated.
You will do that in the didSelectRowAtIndexPath. Here you prepare the view you want to present and push it into the your navigationController. For instance:
// On user tap, present the details you want.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [[DetailViewController alloc] initWithDictionary:dict];
[self.navigationController pushViewController:detail animated:YES];
}
Additionally, these are some relevant links for what you are trying accomplish:
-Navigation Controllers
-Table Views
Do the selection part in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I know this question has been asked before, but no one has really answered it.
I am trying to make an app with a static table view and a Done/Edit button in the top-right corner. I need to be able to hide a cell when it is in one state, and display that cell when it is in the other state. Also I need to be able to add cells when the user selects something. I all ready have the bool in place to detect the change of the Done / Edit button.
So basically my question would be: how do you go about making the table view display the cell when the user presses the button, and hide it when the user presses it again.
And how to add the static cells through the code.
Thanks!
I haven't really looked at the static table stuff in iOS 5 because I believe that requires storyboards, which I don't use.
This can be easily accomplished with a classical grouped UITableView, however. In your UITableViewDataSource methods merely return different results based on the editing state. If you are using the literal editing mode of the UITableView you could do something like the following (warning: typed in browser):
– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if ([tableView isEditing]) {
// Return number of sections when editing
}
else {
// Return number of sections when not editing
}
}
– (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
if ([tableView isEditing]) {
// Return number of rows in section when editing
}
else {
// Return number of rows in section when not editing
}
}
// etc.
I don't recall whether the -setEditing: transition handles animation for you, but if it doesn't then you will want to use -insertRowsAtIndexPaths:withRowAnimation: and related methods to notify the table view that the number of rows, sections, etc. has changed and that it should animate to the new layout. Finally, if you are adding/removing multiple rows/sections, as always you probably want to wrap your work in a -beginUpdates/-endUpdates pair so that the animations are all coalesced.
I've got a basic restaurant menu system for the iPad using storyboards, and I have a product view with a button to add the item to the order page, how can I get it so that when the user presses the add to order button it adds the product name to the order scene. I've thought about using a table view in the order page but I don't know if that was a good idea. Mainly I just need some help on how to get it to print the corresponding product name onto the order page when the button is pressed. Any ideas?
Thanks,
Aislinn
how can I get it so that when the user presses the add to order button it adds the product name to the order scene.
You're mixing up presentation and data, which is a bad idea. Create a representation of orders that has no view logic at all. When a button is pressed to add something to an order, the view controller should tell the class that manages orders to do so. When you need to display an order, the view controller should ask the class for the details. For more information, read up on the MVC design pattern, which Apple uses heavily.
Just add the product name to an NSMutableArray and have the tableview load the items from this array and display it to the user.
Edit:
When the user clicks the button to add the product, use [arrayName addObject:#"Product Name"]. Then, to load it in the tableview, use the tableview's delegate method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{} to load the name into the cell. Something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identity = #"MainCell";
UITableViewCell *cell;
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity] autorelease];
cell.textLabel.text = [arrayName objectAtIndex:indexPath.row];
return cell;
}
I have an app where I need to have two tableviews swapped in and out by once view controller. I currently have it set so the viewcontroller is the delegate and datasource to both, so I use if / else statements in the delegate / datasource methods to determine which tableview to perform the action on like below:
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == [self selectAnAlbumTableView])
{
return [[self albums] count];
}
else
{
return ceil([[self album] numberOfAssets] / 4.0);
}
}
However, I saw this in another thread: "One method which I have often used is to actually have the delegates and data source for the two UITableViews be different objects. This way, your view controller doesn't have to switch back and forth, and your code is overall cleaner and simpler." My question is, how would you go about implementing something like this, ie separate objects for the delegate / datasource, and is it better than what I'm currently doing?
See at most elementary level: I would recommend you not to play with two table view controllers .Just use a navigatorcontroller and push a view based on your requirement. Its much easier to call you different view controller classes than play with two table views in same controller.
It depends. Both has its own advantages and disadvantages. I believe both of your tableview are in a viewcontroller. If both delegate and data source are in different class (Mostly inherited from NSObject)then, in delegate method like tablewviewDidSelectRowAtIndexPath you wont be able to push a view controller or access /set label of viewcontroller directly. You have to use your own delegate method from data/delegate source of tableView back to viewcontroller.
I write an App that shows all it's information in a UITableView.
Now I use the UIViewController to show 2 UITableViews inside of it.
The first UITableView shows the primary information ( this works fine ).
But now I want to show an advertisement in my App.
I decided to use a second UITableViewController with just one UITableViewCell, which isn't scrollable. ( this second UITableViewController is shown and useable )
The very big question for me is how can I show advertisements there?
I like to show something like a video which I could make with Adobe CS4.
The phone doesn't like Flash, so which format could I use and how can I play it in an UITableViewCell?
Or, when it's better to show it in an UIView or something else, let me know.
Greetz
Wissensdurst
There's an inbuilt ad banner class, and they're also launching a video ad service early next year. Or you could override UITableViewCell to include a video player in it which could play your ad.
Why do you want to use a second TableView Controller? Just us the same and check for the indexPath.row or indexPath.section in you UITableView Delegate Methods. For instance:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
//show specific informations
}else if(indexPath.row > 0){
//show comercial
}else{
//show all other rows
}
}
or another thing you can use are the tableHeaderView or the tableFooterView. Those views are imageViews so you just can do e.g.
self.tableView.tableFooterView = (UIImageView*)myImageViewWithCommercialBanner;
For you videos, flash is definitely a no go on iphone. Use the required formats in the Apple Documentations and you are fine. For example *.m4v is a commonly used format for this.