![](/img/trans.png)
[英]How to store NSMutableArray of user defined class objects to file system in iphone?
[英]how to store objects of class file in an array in iphone
我是iPhone应用程序开发的新手。请帮助我。 我正在尝试开发一个需要在表视图中显示联系人姓名和图像的应用程序。我有一个名为Records.h和Records.m的类文件,其中包含三个NSString类型名称,编号和图像的对象。 我从数据库中选择数据,并将每个数据存储在此类文件的对象中,如下所示:
Records *data = [[Records alloc] init];
data.contactname = [NSString stringWithUTF8String: (char *) sqlite3_column_text(stmt, 1)];
data.contactnumber = [NSString stringWithUTF8String: (char *) sqlite3_column_text(stmt, 2)];
data.contactimage = [NSString stringWithUTF8String: (char *) sqlite3_column_text(stmt, 3)];
然后将此类文件存储在NSMutableArray
:
[array addObject:data];
这样,在每个索引处,我的每个对象都具有三个字符串名称,数字和图像。 现在我只想从每个索引中选择名称部分。 任何想法如何做到.. ??
在表格视图的cellForRowAtIndexPath方法中,编写以下代码:
Records *shareObj = [array objectAtIndex:indexPath.row];
label.text=shareobj.name;
label2.text=shareobj.contactnumber;
尝试这个 ::
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Records *objRecord = [array objectAtIndex:indexPath.row];
NSLog(@"Name :: %@", objRecord.name);
lbl.title.text = objRecord.name;
}
谢谢。
//in . h file
@property (strong, nonatomic) UILabel *labelContactName;
@property (strong, nonatomic) UILabel *labelContactNumber;
//in . m file
_labelContactName = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 230, 32)];
_lableContactName.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:_labelContactName];
_labelContactNumber= [[UILabel alloc] initWithFrame:CGRectMake(50, 27, 110, 20)];
_lableContactNumber.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:_labelContactNumber];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Records *objRecord = [array objectAtIndex:indexPath.row];
NSLog(@"Name :: %@", objRecord.name);
_lableContactName.text=objRecord.name;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.