我是iphone app开发的新手。所以请帮帮我。我正在尝试开发一个应用程序,我需要在表视图中显示联系人姓名和图像。我有一个名为Records.h的类文件和有三个NSString类型名称,数字和图像对象的Records.m.我从数据库中选择数据并将每个数据存储在此类文件的对象中,如下所示:
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];
这样在每个索引处我都有每个对象具有所有三个字符串的名称,数字和图像。现在我想从每个索引中只选择名称部分。知道该怎么做.. ??
答案 0 :(得分:0)
在tableview中,cellForRowAtIndexPath方法编写以下代码:
Records *shareObj = [array objectAtIndex:indexPath.row];
label.text=shareobj.name;
label2.text=shareobj.contactnumber;
答案 1 :(得分:0)
试试这个::
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Records *objRecord = [array objectAtIndex:indexPath.row];
NSLog(@"Name :: %@", objRecord.name);
lbl.title.text = objRecord.name;
}
感谢。
答案 2 :(得分:0)
//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;
}