在iPhone开发里面的Table Cell中添加自定义布局View是本文要介绍的内容,主要是来虚席iphone开发中布局的相关内容,来看本文详细内容。
在iPhone开发中,tableView提供了通过nib自定义视图的解决方案。这就使开发者能够完成相当复杂的界面布局。下面介绍table中添加自定义的table cell。实现的效果如下:
实现过程很简单,首先创建一个table视图,添加table相应的协议。
接下来,新建文件,并在 subclass 里 选择 UITableViewCell 这里我命名为 “MyCell”
然后在利用IB创建一个名为mycell的nib,在里面拖入一个UITableViewCell并将其类名改为MyCell。
实现具体的类:
-(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;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
小结:iPhone开发:在Table Cell中添加自定义布局View的内容介绍完了,希望通过本文的学习能对你有所帮助!