adi*_*dit 1 iphone objective-c uitableview ipad
我以编程方式创建了我的UITableViewCell(没有xib),这是我在代码中的方式:
- (id) initWithFrame: (CGRect)frame {
self = [super initWithFrame: frame];
if (self) {
NSLog(@"CALLING INIT WITH FRAME");
self.like_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 75, 30, 30)] autorelease];
[self.contentView addSubview: self.like_img];
self.comment_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 110, 30, 30)] autorelease];
[self.contentView addSubview: self.comment_img];
self.type_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 40, 30, 30)] autorelease];
[self.contentView addSubview:self.type_img];
self.avatar = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)] autorelease];
[self.contentView addSubview:self.avatar];
self.post = [[[UITextView alloc] initWithFrame:CGRectMake(40, 40, 650, 100)] autorelease];
[self.contentView addSubview:self.post];
self.post_title= [[[UILabel alloc] initWithFrame:CGRectMake(40, 20, 650, 50)] autorelease];
[self.contentView addSubview:self.post_title];
self.post_detail = [[[UILabel alloc] initWithFrame:CGRectMake(40, 10, 650, 20)] autorelease];
[self.contentView addSubview:self.post_detail];
}
NSLog(@"NOT MY SELF");
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"FTPostCell";
FTPostCell *cell = (FTPostCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"INITIALIZING CELL");
cell = [[[FTPostCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
//snip some code here
return cell;
}
Run Code Online (Sandbox Code Playgroud)
问题是我没有看到它调用initWithFrame被调用,为什么会这样?因此,我所看到的只是空洞...
由于您调用,因此未调用initWithFrame
initWithFrame:reuseIdentifier:
更换
- (id) initWithFrame: (CGRect)frame {
self = [super initWithFrame: frame];
Run Code Online (Sandbox Code Playgroud)
同
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithFrame: frame reuseIdentifier:reuseIdentifier];
Run Code Online (Sandbox Code Playgroud)
另请注意,initWithFrame:reuseIdentifier是一个不推荐使用的方法,您应该使用initWithStyle:reuseIdentifier.
| 归档时间: |
|
| 查看次数: |
2039 次 |
| 最近记录: |