iPhone開發(fā):在Table Cell中添加自定義布局View
在iPhone開發(fā)里面的Table Cell中添加自定義布局View是本文要介紹的內容,主要是來虛席iphone開發(fā)中布局的相關內容,來看本文詳細內容。
在iPhone開發(fā)中,tableView提供了通過nib自定義視圖的解決方案。這就使開發(fā)者能夠完成相當復雜的界面布局。下面介紹table中添加自定義的table cell。實現(xiàn)的效果如下:
實現(xiàn)過程很簡單,首先創(chuàng)建一個table視圖,添加table相應的協(xié)議。
接下來,新建文件,并在 subclass 里 選擇 UITableViewCell 這里我命名為 “MyCell”
然后在利用IB創(chuàng)建一個名為mycell的nib,在里面拖入一個UITableViewCell并將其類名改為MyCell。
實現(xiàn)具體的類:
- -(NSInteger) tableView:(UITableView *)tableView
- numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"CustomCellIdentifier";
- MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"mycell" owner:self options:nil];
- cell = [array objectAtIndex:0];
- [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
- }
- [[cell lable] setText:@"你好"];
- //[[cell imageView] setImage:[UIImage imageNamed:[imageNameArray objectAtIndex:indexPath.row]]];
- //[[cell nameLabel] setText:[nameArray objectAtIndex:indexPath.row]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 90;
- }
小結:iPhone開發(fā):在Table Cell中添加自定義布局View的內容介紹完了,希望通過本文的學習能對你有所幫助!