【问题标题】:iPhone UITableView with Multiple Sections具有多个部分的 iPhone UITableView
【发布时间】:2010-06-23 15:02:30
【问题描述】:

抱歉,如果这是一个简单的问题,但谷歌搜索无法帮助我。 我计划在表格视图中显示 3 个数据数组,每个数组在表格视图的不同部分中。

谁能给我一个链接到一个很好的教程或可以帮助我的示例代码?

如果这是一个简单的问题和答案,我再次道歉,但我是 Xcode 的新手,正在为此做我的第一个严肃项目。

谢谢!

【问题讨论】:

    标签: iphone arrays uitableview


    【解决方案1】:

    在您的 TableViewController 实现中:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 3;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
     return [[self getDataArray:section]count];//implement getDataArray
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    
        static NSString *CellIdentifier = @"Cell";
    
        NSObject *data = [[self getDataArray:indexPath.section]objectAt:indexPath.row];//implement getDataArray
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
             //add Code to populate cell with data
        }
        return cell;
    }
    

    其他可能实现的方法:

    - (UIView *)tableView: (UITableView *)tableView viewForHeaderInSection: (NSInteger)section
    - (CGFloat)tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section
    

    【讨论】:

    • 非常感谢,我没有意识到它这么简单。无论如何,我已经实现了大部分代码,我只需要完成它!再次感谢您花时间回答。
    • 为什么在网上这么难找到?我已经为此寻找了几天。
    猜你喜欢
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    相关资源
    最近更新 更多