2011-10-18 4 views
1

私はいくつかのデータを保持する責任があるいくつかの四角形のために画面上にいくつかのスペースを割り当てたいとします。私はそれが3行のテーブルビューになると思っていますカスタムビューセクションを作成する方法は?

外形を表すオブジェクトは何ですか、ボックステーブルは座りますか?

/-----------\ 
| some txt | 
| more txt | 
| other txt | 
\-----------/ 

/-----------\ 
| some txt | 
| more txt | 
| other txt | 
\-----------/ 

私はそれunclickable UIButton作ることができると仮定しますが、内部のUITableView置くことは厄介なようです。

ストックアプリケーションではどうですか?上部にはセクションがあり、下部にはセクションがあります。

答えて

2

あなたはのtableViewごとに異なるヘッダがありますのtableViewのための1つを、あなたは青のショーのsectionHeadersながら、tableViewHeaderイストグリーン各セクション

のための1つを持つことができます。

enter image description here

-(void) viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    if (headerView == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"DetailContactHeader" owner:self options:nil]; 
     headerView.nameLabel.text = [NSString stringWithFormat:@"%@ %@", 
                [contact objectForKey:@"name"], 
                [contact objectForKey:@"familyname"]]; 
     if ([[contact allKeys] containsObject:@"pictureurl"]) { 
      headerView.avatarView.image = [UIImage imageNamed:[contact objectForKey:@"pictureurl"]]; 
     } 
    } 
    [self.tableView setTableHeaderView: headerView]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [[contact allKeys] count]-3; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView  
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 
             reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    id key = [self.possibleFields objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [NSString stringWithFormat:@"%@", key]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [contact objectForKey:key]]; 
    return cell; 
} 

-(CGFloat) tableView:(UITableView *)tableView 
    heightForHeaderInSection:(NSInteger)section 
{ 
    return 44.0; 
} 

-(UIView *) tableView:(UITableView *)tableView 
viewForHeaderInSection:(NSInteger)section 
{ 
    UILabel *l = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease]; 
    l.backgroundColor = [UIColor clearColor]; 
    l.text= @"I am a Section Header"; 
    return l; 
} 

あなたはここに、このアプリケーションのコードを見つけます:MyContacts

任意の…header…方法については、対応する…footer…方法があります。

これはStockアプリでどのように行われるのですか、私はちょうど推測できます:私は何とか似ていると思います。

これが適切な解決策であるかどうかを判断するには、十分な情報を提供しないでください。しかし、私はそう思います。

関連する問題