2010-01-05 24 views
0

我使用默認樣式表格,
我想向表格中添加更多行,我如何定製它?iphone代碼 - 使用自定義表格而不是默認表格

代碼:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
            reuseIdentifier:CellIdentifier] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
} 

// Leave cells empty if there's no data yet 
if (nodeCount > 0) 
{ 
    // Set up the cell... 
    ARecord *aRecord = [self.entries objectAtIndex:indexPath.row]; 

    cell.textLabel.text = aRecord.lDate; 
    cell.detailTextLabel.text = aRecord.WNum; 

    // Only load cached images; defer new downloads until scrolling ends 
    //(!aRecord.appIcon) - use icon 
    if (!aRecord.appIcon) 
    { 
     if (self.tableView.dragging == NO && self.tableView.decelerating == NO) 
     { 
      [self startIconDownload:aRecord forIndexPath:indexPath]; 
     } 
     // if a download is deferred or in progress, return a placeholder image 
     cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];     
    } 
    else 
    { 
     cell.imageView.image = aRecord.appIcon; 
    } 

} 

return cell; 

}

回答

1

不知道我明白這個問題。表中的部分和行數由表視圖的UITableViewDataSource控制(在大多數代碼示例中,該協議由視圖的控制器實現,但它可能是一個單獨的對象)。

您發佈的代碼會在這個過程後期發揮作用:在視圖確定有多少行存在,總數以及哪些行當前在屏幕上並需要呈現這些行之後。但是,一般來說,它和UITableViewDelegate協議的其他方法是您如何定製表格的外觀和行爲。 (與視圖本身的屬性一起)。

1

中行的實現代碼如下數由你

返回什麼決定的 - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection :(NSInteger)部分

如果你在那裏返回500,你將有一個500行表。

0

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

- (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分 { 返回[tblArray計數]; }

- (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath { 的NSString * CellIdentifer = [NSString的stringWithFormat:@ 「%i」 的,indexPath.row]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer]; if(cell == nil){cell = [self myCustomCell:CellIdentifer dicToSet:[tblArray objectAtIndex:indexPath.row]]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } return cell; }

- (的UITableViewCell *)myCustomCell:(的NSString *)CellIdentifer dicToSet:(的NSDictionary *)dicToSet { 的UITableViewCell *細胞= [[[UITableViewCell中的alloc] initWithFrame:方法CGRectMake(0,0,320,44) reuseIdentifier:CellIdentifer] autorelease];

UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(2, 2, 40, 40)]; 
[imgV setImage:[UIImage imageNamed:[dicToSet valueForKey:@"Photo"]]]; 
[cell addSubview:imgV]; 
[imgV release]; 




return cell; 

}