ios - UITableView 动态部分

标签 ios iphone ipad uitableview

我正在使用一个使用动态部分的 TableView ,我有一个包含部分标题的 sectionArray 和另一个包含所有部分的全部数据的数组, 我不知道如何为每个部分的行编写单元格,因为它是动态的

代码是:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return [appDelegate.sectionArray count];
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
  return [appDelegate.appNameArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  UILabel *AppNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(80, 0, 120, 30)];
  [AppNameLabel setBackgroundColor:[UIColor clearColor]];
  [AppNameLabel setText:[NSString stringWithFormat:@"%@",[appDelegate.appNameArray objectAtIndex:indexPath.row]]];
  [AppNameLabel setFont:[UIFont systemFontOfSize:14]];
  [cell.contentView addSubview:AppNameLabel];
  return cell;
}

在 appname 数组中,我有包含所有部分的数据,我需要为特定部分进行隔离,如何在行索引的单元格中创建它,请帮助。

提前致谢。

最佳答案

无需为 sectionTitle 和 appName 创建两个不同的 array。使用对象的 NSDictionary 创建源 NSArrayNSDictionary 对象包含作为 values 的 appName 数组和作为 key 的 sectionTitle。

sourceArray
(
 dictionaryObject1
 {
 key : sectionTitle,
 value : ( appName1,appName2,appName3)
 },
 dictionaryObject2
 {
 key : sectionTitle,
 value : ( appName1,appName2,appName3)
 },
.
.
.
)

关于ios - UITableView 动态部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765300/

相关文章:

ios - 如何在 objective-c 中获取周数的开始和结束日期

iphone - 从 Master 到 Detail UITableView,其中第二个具有分组样式

iphone - 在iOS中创建声音

ios - UIButton 的子类使用 Interface Builder 连接到父 View Controller 的 IBAction?

ios - 在 AVAudioSession 中使用蓝牙播放

iphone - 使用在线服务的可靠iPhone应用程序的提示

iphone - 表格单元格的奇怪行为

html - 媒体查询最大宽度 992px 不适用于 ipad 横向 View

iphone - 画图应用的 OpenGL ES 内容截图

ios - 2 iAds 在模拟器上