I am working in a app where i have data in UITableView
. It is like a drill down application. User will click on a row and will go to next page showing more records in a UITableView
. But problem in my case is that i dont know upto how many level user can drill. The number of levels are not fixed. So now i am thinking to create and add the viewcontrollers programmatically. Is it possible?? if yes how?
thanks in advance.
views:
594answers:
3
A:
Here's a starting point:
http://chris-software.com/index.php/2009/04/29/creating-a-view-programmatically/
Joost Schuur
2010-04-22 06:40:22
it s about creating uiView programmically but i need to create UIViewController programmically..........
pankaj
2010-04-22 06:44:16
A:
UIViewController *controller = [[UIViewController alloc] init];
controller.view = whateverViewYouHave;
Do you have your own view controller that you coded? In that case you probably don't need to set the view property as it has been set in IB if that is what you used. When you have your controller you can push it onto the navigationController or view it modally etc.
willcodejavaforfood
2010-04-22 06:54:44
Right now i am on a viewcontroller and want to direct the user to new viewcontroller and display data in a tableview
pankaj
2010-04-22 07:10:38
and yes, one more thing user can also further drill down to next level from this new programmically created viewcontroller
pankaj
2010-04-22 07:11:30
Then you probably want your first view controller to be a UINavigationController.
willcodejavaforfood
2010-04-22 08:21:55
A:
UIViewController
s are always created programmatically. It sounds like you just need to have the same class for each level of view controller, e.g.:
//CoolViewController:UITableViewController
//CoolViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!self.isAtTopLevel) {
CoolViewController *cvc = [[CoolViewController alloc] initWithRecord:[self.records objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:cvc animated:YES];
[cvc release];
} else {
//do something else
}
}
In this case, thingies
would be some sort of recursive NSArray (i.e. an array of arrays).
eman
2010-04-22 06:58:18
Thanks eman for answer, in this new view controller i need to display a UITableview with records. How will i do that?
pankaj
2010-04-22 07:09:29
and yes, one more thing user can also further drill down to next level from this new programmically created viewcontroller
pankaj
2010-04-22 07:12:08
(updated example) In this example, each table view controller would have an array of records, each of which would have an array of sub-records (correct me if I'm not understanding the design correctly). So you could have a class called `Record`, which would have a name (displayed on the table cell) and an `NSArray` of `Record`s--each table view controller would display the array of sub-records.
eman
2010-04-22 07:41:37
according to ur last comment i will have have to bring all rows from my database and save it. It is not my possible as that way i will be ended up saving hundreds of thousands of rows and only using only few of them
pankaj
2010-04-22 08:34:07
@pankaj: it's hard to know your desired design based on your description. Can you post more specifics? (Are you using Core Data?)
eman
2010-04-22 08:50:35
ok, i m having a tableview where i am showing some data fetched from web services. There could be thousands of rows in the database but i want to display them in a drill down way as there is some relation in them. Now on first page i display main categories. When user selects any one of them it will display the further sub categories. I dont know upto how many levels i will be getting the records, so i cant have a fixed number of viewcontrollers. So i trying to generate them programmically. When user selects a row i want to create a view controller, display it with tableview and records....
pankaj
2010-04-22 09:14:02
.... and when user selects any of the row in that table view(created dynamically) it should again be redirected to new view controller(dynamically created). I hope i am more clear now
pankaj
2010-04-22 09:15:47