2013-03-18 3 views
0

저는 아이폰 앱 개발에 새로운입니다. 제발 도와주세요. 나는 연락처 이름 번호와 이미지를 테이블보기에 표시해야하는 응용 프로그램을 개발하려고합니다. NSString 유형 이름, 숫자 및 이미지의 세 객체를 갖는 Records.h 및 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]; 

등 그 모든 인덱스 나는 세 개의 문자열 이름, 번호 및 이미지를 가진 각각의 객체를 가진다. 이제 모든 인덱스에서 이름 부분 만 선택하려고합니다. 어떤 생각인지 어떻게 .. ?? 다음 코드를 당신의 tableview의 cellForRowAtIndexPath 방법을 쓰기에

+0

단순 코드는 아래에 추가 확인하십시오 당신의 tableview 데이터 소스 방법 : cellForRowAtIndexPath : 기록 * 기록 = 배열 ​​objectAtIndex : indexpath.row]; 이제 가져올 수 있습니다, record.contactname, record.ctnumber, record.ctimage 등 – Mrunal

+1

근무 .. !! 감사합니다 Mrunal .. :) – Paul

+0

나는 이것을 구현했습니다. 그러나 나는 문제에 직면하고있다. 매번 레이블에 동일한 텍스트가 표시됩니다. 나에게는 폴과 존이라는 두 개의 이름이 있습니다. 그러나 테이블보기에서 두 셀 모두 같은 이름의 폴을 표시합니다. 선택 쿼리가 데이터베이스에서 올바른 데이터를 반환하고 있습니다. 다음은 코드입니다 : data = [namelist objectAtIndex : indexPath.row]; UILabel * lbl; lbl = (UILabel *) [셀 뷰 와이즈 태그 : 1]; lbl.text = data.contactname; – Paul

답변

0

:

Records *shareObj = [array objectAtIndex:indexPath.row]; 
label.text=shareobj.name; 
label2.text=shareobj.contactnumber; 
+0

이것을 구현했습니다. 그러나 나는 문제에 직면하고있다. 매번 레이블에 동일한 텍스트가 표시됩니다. 나에게는 폴과 존이라는 두 개의 이름이 있습니다. 그러나 테이블보기에서 두 셀 모두 같은 이름의 폴을 표시합니다. 선택 쿼리가 데이터베이스에서 올바른 데이터를 반환하고 있습니다. 코드는 다음과 같습니다. data = [namelist objectAtIndex : indexPath.row]; UILabel * lbl; lbl = (UILabel *) [cell viewWithTag : 1]; lbl.text = data.contactname; – Paul

+0

코드 cellForRowAtIndexPath 메서드를 볼 수 있습니다 –

+0

이제 문제가 해결되었습니다. 사실 나는 새로운 객체를위한 메모리를 생성하지 못하게함으로써 오직 한 번만 클래스의 객체를위한 메모리를 할당했다. 레코드 * 데이터 = [[레코드 할당] 초기화]; 나는 이것이 실제로 잘못된 장소라고 선언했다. – Paul

0

이 시도 ::

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    Records *objRecord = [array objectAtIndex:indexPath.row]; 
    NSLog(@"Name :: %@", objRecord.name); 

    lbl.title.text = objRecord.name; 
} 

감사합니다.

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; 
} 
관련 문제