在 ios 中覆盖 UItable View Cell 中的内容 [英] overwritting of contents in UItable View Cell in ios

查看:25
本文介绍了在 ios 中覆盖 UItable View Cell 中的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表格视图单元格中,我需要在单个单元格中显示数组元素的内容,如果我插入任何新内容,则不会覆盖先前的内容.应按顺序显示先前的内容和我的新内容.这是我的代码

In my table view cell i need to display the contents of my array elements in a single cell and if i insert any new contents the previous contents are not to be overwritten.The previous content and my new content should be displayed in order.Here is my code

- (void)viewDidLoad
{
[super viewDidLoad];


NSArray *arr=[NSArray arrayWithObjects:cnfqty,cnftitle,cnfrate, nil];

//cnfqty,cnftitle,cnfrate are NSString

finarray=[[NSMutableArray alloc]init];
[finarray addObjectsFromArray:arr];
NSLog(@"%@",finarray);


}

- (void)viewDidUnload
{
[super viewDidUnload];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [finarray count];
}

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

{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 40, 20)];
    lab.text=[finarray objectAtIndex:indexPath.row];
    [cell.contentView addSubview:lab];

}
// Configure the cell...

return cell;
}

我的代码面临的问题是每个字符串都显示在每个单元格中,如果我插入任何新字符串,以前的内容就会消失,只显示新内容.

The problem which i'm facing with my code is each string is displayed in each cell and if i insert any new string previous contents are gone and only new contents are displayed.

为了清楚地了解这个问题,我正在尝试为在线购物实施添加到购物车"服务.根据概念,必须从各种产品中添加项目,并保存产品信息并显示详细信息在表格视图中.但我不明白..

To get clear idea about this question i'm trying to implement "add to cart" service for online shopping.As per concept the items have to be added from various products and it saves the product info and have to display the details in Table view.But i'm not getting it..

请指导..提前致谢..

Kindly Guide please..Thanks in advance..

推荐答案

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

         UITableViewCell *cell = (UITableViewCell*)[self.YourTableName dequeueReusableCellWithIdentifier:nil];        
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
      }
      
      
          return cell; 
      }
      

      使用 ReusablecellIdentifier nil 使其正常工作......

      use ReusablecellIdentifier nil so it working correctly.....

      这篇关于在 ios 中覆盖 UItable View Cell 中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆