2012-02-23 2 views
0

데이터베이스의 데이터를 그룹화 된 스타일의 테이블보기에 채우고 싶습니다. 레코드 수는 다양 할 수 있습니다. (동적으로 변경)그룹 스타일의 iPhone에서 테이블보기

시도했지만 머리글이있는 테이블 뷰에서 다른 섹션을 만들 수 있습니다.

EX : 내 데이터베이스에는 5 개의 이름, 주소, 연락처, 매출액, 기술이 있습니다.

그래서 내가 수행 한 섹션의 머리글에 이름 필드 값을 넣으 려합니다 ..... 하지만 다른 섹션의 값을 채우려고 할 때 섹션의 값이 1 개만 채워집니다 만.

두 번째 문제점은 화면을 위아래로 스크롤 할 때 값이 잘못 배치되면 임의로 위치가 변경된다는 것입니다.

+1

곧 코드를 보도록 요청할 것이라고 생각합니다. 특히 테이블을 채우는 데 사용하는 것. –

+1

코드를 Google에 알려주십시오. 특히 cellForRowAtIndexPath. –

+0

코드를 추가했습니다 .... plz 수정 rowforindex 부분 – Mania

답변

0

numberOfSectionsInTableView 및 numberOfRowsInSection이 올바르게 완료되었는지 확인하십시오. 또한 cellForRowAtIndexPath는 각 섹션 내의 섹션과 행을 식별하기 위해 코딩되어야합니다. 완전한 예제가 필요한 경우 지금 사용하고있는 코드를 TableView에 게시하십시오. 원하는 코드를 수정하여 수정할 수 있습니다. 테이블 뷰 귀하의 .H 파일에 위임하고이 형식을 따라야합니다

5

먼저 수입, 여기

@interface CustomtableViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource> 
{ 
    UITextField * username; 
    UIButton * submit; 
} 

@implementation CustomtableViewController 

- (void)viewDidLoad 
{ 
    UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(10, 70, 300, 45)]; 
    submit = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [submit setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    //[submit setTitleColor:[UIColor colorWithWhite:0.0 alpha:0.56] forState:UIControlStateDisabled]; 
    [submit setTitle:@"Login" forState:UIControlStateNormal]; 
    [submit.titleLabel setFont:[UIFont boldSystemFontOfSize:14]]; 
    [submit setFrame:CGRectMake(10.0, 15.0, 280.0, 44.0)]; 
    [newView addSubview:submit]; 

    [self.tableView setTableFooterView:newView]; 

    [super viewDidLoad]; 

} 

    #pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
#warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return 2; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     //self.tableView.contentOffset = CGPointMake(10, 320); 
     [self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)]; 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    if ([indexPath section] == 0) { 
     username = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
     username.adjustsFontSizeToFitWidth = YES; 
     username.textColor = [UIColor blackColor]; 
     if ([indexPath row] == 0) { 
      username.placeholder = @"[email protected]"; 
      username.keyboardType = UIKeyboardTypeEmailAddress; 
      username.returnKeyType = UIReturnKeyNext; 
      cell.textLabel.text = @"Username"; 
      username.clearButtonMode = YES; 
     } 
     else { 
      username.placeholder = @"minimum 6 characters"; 
      username.keyboardType = UIKeyboardTypeDefault; 
      username.returnKeyType = UIReturnKeyDone; 
      username.secureTextEntry = YES; 
      cell.textLabel.text = @"Password"; 
      username.clearButtonMode = UITextFieldViewModeAlways; 
     } 
     username.backgroundColor = [UIColor whiteColor]; 
     username.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support 
     username.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support 
     username.textAlignment = NSTextAlignmentLeft; 
     username.tag = 0; 


     username.clearButtonMode = UITextFieldViewModeAlways; // no clear 'x' button to the right 
     [username setEnabled: YES]; 


    [cell.contentView addSubview: username]; 

     } 

    // Configure the cell... 

    return cell; 
} 

, 나는 사용자 이름과 암호에 대한 두 텍스트 필드를 만들었습니다. else if 조건을 사용하여 필요에 따라 각각의 연속 행에 텍스트 필드를 삽입 할 수 있습니다.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    return [NSString stringWithFormat:@"User Login"]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 

    return 50; 
} 


- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { 

    return @""; 

} 

그래서, 여기 내 코드는 두 개의 텍스트 필드 (사용자 이름 및 암호)와 로그인 버튼으로 로그인 페이지를 만드는 데 사용됩니다. 필요에 따라 코드를 수정할 수 있습니다. 건배!

+1

감사합니다 Ajit, 좋은 설명. +1. :) – NSExpression