开发者

UITableViewController isn't pushing views onto the stack

开发者 https://www.devze.com 2023-03-26 14:55 出处:网络
I have a UITableViewController that has a UISearchbar in its header view. When the user searches, my UITableView populates with the results. I want to push a new view controller onto the stack when th

I have a UITableViewController that has a UISearchbar in its header view. When the user searches, my UITableView populates with the results. I want to push a new view controller onto the stack when the user selects a result.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if (cell.accessoryType == UITableViewCellAccessoryNone) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;

        WatchlistSheetView* watchlistSheetView = [[WatchlistSheetView alloc] initWithNi开发者_如何转开发bName:@"WatchlistSheetView" bundle:nil];
        watchlistSheetView.symbol = cell.textLabel.text;
        [self.navigationController pushViewController:watchlistSheetView animated:YES];
        [watchlistSheetView release];

        //[self dismissModalViewControllerAnimated:YES];
    }     
}

The following doesn't push a view controller onto the stack. Nothing happens. How can I resolve?


I guess that self.navigationController is nil, so that the message pushViewController is sent nowhere.

To fix this, you can create a UINavigationController in your application:didFinishLaunching and push your table view controller on to it as its root controller, along these lines:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    UINavigationController* navigation = [[UINavigationController alloc] init];

   ....
   [navigation pushViewController:yourTableViewController animated:NO];
   ...
   [window addSubview:[navigation view]];
   [self.window makeKeyAndVisible];
}

or you could use initWithRootController to initialize the navigation view controller with your table view controller.


It appears that you are calling self when referencing your navigation controller. Did you actually allocate a navigation controller and assign it to self?

0

精彩评论

暂无评论...
验证码 换一张
取 消