【发布时间】:2010-06-23 15:02:30
【问题描述】:
抱歉,如果这是一个简单的问题,但谷歌搜索无法帮助我。 我计划在表格视图中显示 3 个数据数组,每个数组在表格视图的不同部分中。
谁能给我一个链接到一个很好的教程或可以帮助我的示例代码?
如果这是一个简单的问题和答案,我再次道歉,但我是 Xcode 的新手,正在为此做我的第一个严肃项目。
谢谢!
【问题讨论】:
标签: iphone arrays uitableview
抱歉,如果这是一个简单的问题,但谷歌搜索无法帮助我。 我计划在表格视图中显示 3 个数据数组,每个数组在表格视图的不同部分中。
谁能给我一个链接到一个很好的教程或可以帮助我的示例代码?
如果这是一个简单的问题和答案,我再次道歉,但我是 Xcode 的新手,正在为此做我的第一个严肃项目。
谢谢!
【问题讨论】:
标签: iphone arrays uitableview
在您的 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
【讨论】: