How do I create a UIViewController programmatically?

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.

Answers


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.


UIViewControllers 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).


Need Your Help

JavaFX HTMLEditor - Insert image function

java html image wysiwyg javafx-2

I'm using JavaFX integrated HTMLEditor. All the functions that it has are fine but I need to have also the function of inserting an image inside the HTML text.

Input inside Fancybox

jquery input fancybox

I have a very strange problem with Fancybox.