【发布时间】:2016-07-26 14:51:19
【问题描述】:
我希望 TableViewCellContentView 与 TableView 具有相同的宽度,代码如下:
#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong) UITableView* mainTableView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds)-20)];
_mainTableView.delegate = self;
_mainTableView.dataSource = self;
[self.view addSubview:_mainTableView];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier];
}
cell.textLabel.text = @"111fewfwFwfrg";
cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"me_today_arrow.png"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
//(lldb) po cell
//<UITableViewCell: 0x13dd22bf0; frame = (0 220; 768 44); text = '111fewfwFwfrg'; autoresize = W; layer = <CALayer: 0x13dd1cf30>>
//(lldb) po cell.contentView
//<UITableViewCellContentView: 0x13c6521a0; frame = (0 0; 711 43.5); opaque = NO; gestureRecognizers = <NSArray: 0x13c6594b0>; layer = <CALayer: 0x13c6546a0>>
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
@end
这是图片: http://i.stack.imgur.com/QK6a8.jpg
lldb 说 TableViewCellContentView 的框架是 (0 0; 711 43.5),x 值为 0,所以 TableViewCell 中可能有填充,但我找不到任何方法来设置它。顺便说一句,它在 iPhone 上运行良好。
谁能帮我解决这个问题?谢谢。
【问题讨论】:
-
横向和纵向模式一样吗?
-
嗨@zcui93,是的。
标签: ios objective-c uitableview ipad