iphone - 覆盖 UIView :initWithFrame and got nil parameters

标签 iphone objective-c xcode ios

我有一个从 UIView 扩展的类。我用它来创建自定义默认 View 。我使用 -(id)initWithFrame:(CGRect)frame; 但是当我使用初始化程序时,frame 参数始终为 null 值。

代码如下:

#import "SomeView.h"
@implementation POIView
@synthesize theButton;

- (id)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    NSLog(@"%@",frame);
  }
  return self;
}
@end

NSLog 结果总是(null),这是我调用初始化的地方

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 static NSString *CellIdentifier = @"CELL_ID";
 const int THE_TAG         = 1000;

 UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   CGRect *rect = CGRectMake(0, 0, tableView.frame.size.width,tableView.rowHeight);
   someView = [[SomeView alloc] initWithFrame:rect];
 }else{
   someView = (SomeView *) [cell viewWithTag:THE_TAG];
 }
 return cell;
}

我现在在 tableView 上使用它,但我也将 someview 用于一些 UILabel。

最佳答案

frame 是一个结构体,它不是 NSObject 的子类。您可以通过以下方式显示帧值。

NSLog(@"%.2f %.2f %.2f %.2f",frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);

NSLog(@"%@", aObj); 等于NSLog(@"%@",[aObj description]);

关于iphone - 覆盖 UIView :initWithFrame and got nil parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4747494/

相关文章:

javascript - iOS UIWebView Javascript - 插入数据 - 接收回调?

ios - 无法从我的协议(protocol)类调用委托(delegate)方法

ios - CAShapeLayer fillColor 不渲染

objective-c - 使用多个窗口

iphone - 在iTunes Connect中选择正确的 bundle ID。

ios - 如何对齐 UIImage 下面的 UIButton 中的文本,因为它没有正确显示

iphone - NSURLConnection、NSURLRequest 和远程缓存

c++ - 是否有 C++ 等效于 Xcode 7 的 objective-c 的 -debugDescription 方法?

iphone - 如果不再需要,如何正确从其 super View 中删除 View ?

objective-c - 你如何在 NSTableView 中拖拽移动一行?