2014-06-28 22 views
0

我正在创建NSDate对象,我有一个导航栏,我试图保持在屏幕顶部的静态位置。 我希望在导航栏下方创建NSDate对象,但是它们正在导航栏上方创建并向下推导航栏。如何限制导航栏,并防止它移动

Before adding date elements After adding date elements

这是我insertNewObject功能

- (void)insertNewObject 
{ 
if (!_objects) { 
    _objects = [[NSMutableArray alloc] init]; 
} 
[_objects insertObject:[NSDate date] atIndex:0]; 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 

我怀疑它有这个功能,调用insertNewObject方法来做。具体来说,我相信自我调用意味着它告诉它在ViewController的顶部创建它。

- (IBAction)addData:(id)sender { 
// call insertNewObject 
[self insertNewObject]; 
} 

如何约束我的导航栏并防止在导航栏上创建新的NSDate对象?

回答

1

如果你想使用导航栏(不是导航控制器),那么你需要使用UIViewController而不是UITableViewController。 UITableViewController的视图是表视图,所以添加到视图的任何东西都会成为表的子视图。使用UIViewController,您可以在顶部添加导航栏,然后在下面添加表格视图。您必须为表视图添加一个IBOutlet,并使控制器成为您的表的数据源和委托(当您使用UITableViewController时,这些东西是自动的)。

当然,替代方法是将UITableViewController嵌入到导航控制器中。