开发者

Add "details view" to UITableView

I have a UITabbar with multiple view controllers. One of them is a UITableView. The tableview is stored in a nib where the file owner is a UITableViewController.

I'd like the tableview to show a "detail view" (custom view with a UILabel and some other elements) once a table cell is selected. My approach was to add the new details view as a child view to the UITableView:

[self.view addSubView:[detailsViewController view]]

Unfortunately that doesn't create the effect I want. As a subview of the UITableView, I can scroll beyond the added details view and see the underlying table entries. UINavigationBar is an option, but since there's no deeper hierarchy, I'd prefer a simple custom view with开发者_JAVA百科 a close button. Any suggestions?


Replace your UITableViewController with a UIViewController. Then add a UITableView to your view controller. Set the delegate and datasource of your table view to your view controller. Now you can add a subview in a non-scrolling view-controller, still having your tableview :).

Edit: Or, you can stop the tableview from scrolling when the popupview appears.

[(UIScrollView *)self.view setScrollEnabled:NO];
CGRect rect = self.popupview.frame;
rect.origin.y = [(UIScrollView *)self.view contentOffset].y;
self.popupview.frame = rect;


If you simply want to create a popup (Modal View)] when the user clicks a specific Cell, do the following.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// If the view you want to present modally is called DetailViewController, do the following.

DetailViewController *dvCon = [[dvCon alloc] initWithNibName:@"DetailViewController" bundle:nil];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:dvCont];
[self presentModalViewController:navigationController animated:YES];

[navigationController release];
[dvCont release];   


}

Good luck!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜