简体   繁体   English

客户 UITableview 调用方法将值存储在 iphone 的单元格中

[英]custome UITableview calling methods to store value in cell in iphone

I am using custom UITableview concept to show data in cell of tableview.我正在使用自定义 UITableview 概念在表格视图的单元格中显示数据。 My custome uiTableview name is CustomeUITableView.h,CustomeUITableView.m and CustomeUITableView.xib file.我的客户 uiTableview 名称是 CustomeUITableView.h、CustomeUITableView.m 和 CustomeUITableView.xib 文件。 This file is consisting following code.该文件由以下代码组成。

//header file code

@interface CustomTableCellview : UITableViewCell {

UILabel *titleOfPost;
IBOutlet  UILabel *userProfileName;
}

@property(nonatomic,retain) IBOutlet UILabel *titleOfPost;


- (void)setTileOfPost:(NSString *)_text;
- (void)setUserName:(NSString *)_text;
@end

// some important part of class file code

- (void)setTileOfPost:(NSString *)_text{
titleOfPost.text = _text;
 }

- (void)setUserName:(NSString *)_text{

userProfileName.text = _text;

 }

// TableView code where cell is creating and function of cutome UITableview is calling

    static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"tblCellView";

   CustomTableCellview *cell = (CustomTableCellview *)[tableView  dequeueReusableCellWithIdentifier:MyIdentifier];
  if(cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"CustomTableCellview" owner:self options:nil];
    cell = tblCell; //IBOutlet CustomTableCellview *tblCell;

 }

[cell setTileOfPost:[tableList objectAtIndex:indexPath.row]];

[cell setUserName:[profileUserName objectAtIndex:indexPath.row]];

 return cell;    

This is calling well and my output is displaying data fine.这很好,我的 output 显示数据正常。 But here is a bit mistake.但这里有点错误。 I am calling function "setTileOfPost" and "setUserName" in each CELL load.我在每个 CELL 负载中调用 function “setTileOfPost”和“setUserName”。 This is making large function calling.这是进行大型 function 调用。 I want to fetch all title of text in one call of function.我想在 function 的一次调用中获取所有文本标题。 I don't want to use calling function again and again.我不想一次又一次地调用 function。 I stored value in "tableList" and this is extern array defined in main.m file so I can use this array anywhere in application.我将值存储在“tableList”中,这是在 main.m 文件中定义的外部数组,因此我可以在应用程序的任何地方使用该数组。

How to grab all value in single function call?如何在单个 function 调用中获取所有值? Thanks in advance提前致谢

tableList and profileUserName are of type NSArray or NSMutableArray i suppose.我想tableListprofileUserName的类型是 NSArray 或 NSMutableArray 。 What you can do is in your viewdidLoad method create a copy of these arrays as the data source.您可以做的是在您的 viewdidLoad 方法中创建这些 arrays 的副本作为数据源。 And in cellforrowatindexpath you can directly access these copies.在 cellforrowatindexpath 中,您可以直接访问这些副本。

[cell.title setText:[tableListCopy objectAtIndex:indexPath.row]];

I hope you get the point here.我希望你明白这里的意思。 You are having a local copy of the datasource of the tableview.您拥有 tableview 数据源的本地副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM