2011-10-18 46 views
1

假設我想在屏幕上分配幾個矩形的空間,每個矩形負責保存一些數據。我認爲這將是一個3行的TableView如何創建自定義視圖部分?

表示外部形狀的對象是什麼,盒子表將坐在?

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

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

我想我可以使它成爲一個不可點擊的UIButton,但把裏面的UITableView似乎很尷尬。

股票申請是如何完成的?頂部有一個部分,底部有一個部分。

回答

2

你必須每的tableView不同的頁眉:一爲的tableView,你可以有一個部分一個

綠色IST的tableViewHeader,而藍色顯示sectionHeaders。

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…方法。

它是如何做在股票應用程序,我只能猜測:我覺得有點類似。

要判斷這是否適合您的解決方案,您無法提供足夠的信息。但我認爲是。