【问题标题】:UItableview inside a view based application基于视图的应用程序中的 UItableview
【发布时间】:2011-09-18 02:21:05
【问题描述】:

我在视图中有一个基于视图的应用程序和一个 UITableview。 当我单击 tableview 时,我将 dataSource 、 delegate 和 tableView 设置为“File's Owner” 然后单击 Files 所有者,我将 tableView 设置为 Table View , view 设置为 View , datasource 设置为 Table View 并委托给网点中的 Table view 。

- (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 需要不同的实现。如果有人能指导我如何正确显示此内容,我将不胜感激。谢谢。

【问题讨论】:

    标签: iphone uitableview xcode4


    【解决方案1】:

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

    【讨论】:

    • 谢谢...这似乎是问题
    【解决方案2】:

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

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
        return 0;
    }
    

    您还需要修复另一个 cellForRowAtIndexPath!

    【讨论】:

    • 太好了——请用复选标记标记你最喜欢的答案:)
    【解决方案3】:

    我将 dataSource 、 delegate 和 tableView 设置为“File's Owner” 单击表格视图,然后单击我设置的文件所有者 tableView 到 Table View , view 到 View , datasource 到 Table View 和 委托给网点中的表格视图。

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多