HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – UITableView与多个部分大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想让tableView与多个部分,但我不想使用字典我有两个数组,我想要第一个数组应该加载在第一部分和第二部分。

我有arrayOne有3个项目和arrayTwo有4个项目,如何添加显示它们的部分。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    if(section == 0)
        return resultArray.count;
    else
        return resultArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSLog(@"number of Sections");
    if(section == 0)
        return @"Section 1";
    if(section == 1)
        return @"Section 2";
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath {
     NSLog(@"Table Cell Data");
     static NSString *CellIdentifier = @"Cell";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reusEIDentifier:CellIdentifier];
     }

     appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];

     if (indexPath.section==0) {    
         appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
         ObjectData *theCellData = [resultArray objectATindex:indexPath.row];
         NSString *cellValue =theCellData.category;
         NSLog(@"Cell Values %@",cellvalue);
         cell.textLabel.text = cellValue;
         return cell;
     }
     else {
         ObjectData *theCellData = [resultArray objectATindex:indexPath.row];
         NSString *cellValue =theCellData.category;
         cell.textLabel.text = cellValue;
         return cell;       
     }
}@H_489_10@

解决方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 2 ;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      if (section==0)
      {
             return [array1 count];
      }
      else{
             return [array2 count];
      }
 }

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
      if(section == 0)
           return @"Section 1";
      else
           return @"Section 2";
 }


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath 
{

      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reusEIDentifier:CellIdentifier];
      }

 if (indexPath.section==0) {
     ObjectData *theCellData = [array1 objectATindex:indexPath.row];
     NSString *cellValue =theCellData.category;
     cell.textLabel.text = cellValue;
 }
 else {
     ObjectData *theCellData = [array2 objectATindex:indexPath.row];
     NSString *cellValue =theCellData.category;
     cell.textLabel.text = cellValue;
 }
     return cell;        
 }@H_489_10@

大佬总结

以上是大佬教程为你收集整理的iphone – UITableView与多个部分全部内容,希望文章能够帮你解决iphone – UITableView与多个部分所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。