iphone – UITableView与多个部分

iphone – UITableView与多个部分,第1张

概述我想让tableView与多个部分,但我不想使用字典我有两个数组,我想要第一个数组应该加载在第一部分和第二部分。 我有arrayOne有3个项目和arrayTwo有4个项目,如何添加和显示它们的部分。 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if( 我想让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;            }}
解决方法
- (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;         }
总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1087427.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存