基于视图的应用程序内的UItableview

时间:2011-09-18 02:21:05

标签: iphone uitableview xcode4

我在视图中有一个基于视图的应用程序和一个UITableview。 当我点击tableview时,我将dataSource,delegate和tableView设置为“File's Owner” 然后单击Files owner我将tableView设置为Table View,查看View,将数据源设置为Table View并委托给出口中的Table视图。

- (void)viewDidLoad
{
    [super viewDidLoad];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)videoView {

    return 1;

}

// Customize the number of rows in the table view.

- (NSInteger)videoView:(UITableView *)videoView numberOfRowsInSection:(NSInteger)section {

    return 0;
}

// Customize the appearance of table view cells.

- (UITableViewCell *)videoView:(UITableView *)videoView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [videoView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

    }

    // Set up the cell...
    return cell;

}


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

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

当我运行模拟器的应用程序时,我收到以下错误 “tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x6029710 “

我觉得tableviews在基于视图的应用程序中使用时需要不同的实现,而不是基于导航的应用程序。如果有人能指导我做正确显示的事情,我将非常感激。谢谢。

3 个答案:

答案 0 :(得分:2)

无论您是在基于视图的应用程序还是基于导航的应用程序中,实现都是相同的。此错误消息告诉您的是您的表视图尝试在其数据源上调用tableView:numberOfRowsInSection:,但数据源未实现具有该名称的方法。当然,查看示例代码,您实现了一个名为videoView:numberOfRowsInSection:而不是tableView:numberOfRowsInSection:的方法。

答案 1 :(得分:0)

对于委托实现,您无法将tableView更改为videoView。应该是:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 0;
}

您还需要修复其他cellForRowAtIndexPath!

答案 2 :(得分:0)

  

当i时,我将dataSource,delegate和tableView设置为“File's Owner”   点击tableview然后点击我设置的文件所有者   tableView到表视图,查看到视图,数据源到表视图和   委托出口的表格视图。

很难理解你在这里做了什么。您将表的数据源设置为表视图本身吗?

  

当我运行模拟器的应用程序时,我收到以下错误   “tableView:numberOfRowsInSection:]:发送到无法识别的选择器   实例0x6029710“

地址0x6029710是什么对象?它肯定是您设置为表的数据源的对象,但它没有实现UITableViewDataSource协议。

  

我觉得tableviews需要不同的实现   在基于视图的应用程序中使用而不是基于导航时   应用

“基于视图的应用”和“基于导航的应用”之间没有什么区别。有“基于视图”和“基于导航”的项目模板,但这些只是您的应用程序的两个不同的起点。 UITableView并不关心你使用哪一个。