переопределение UIView: initWithFrame и получил ноль параметров - PullRequest
1 голос
/ 20 января 2011

У меня есть класс, который расширяется от UIView.Я использовал это для создания пользовательского представления по умолчанию.Я использую -(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.

Ответы [ 2 ]

1 голос
/ 20 января 2011

frame это структура, это не подкласс от NSObject.Вы можете показать значение кадра следующим образом.

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

NSLog (@ "% @", aObj); равно NSLog (@ "% @",[aObj description]);

0 голосов
/ 20 января 2011

Я вижу проблему в том, что CGRectMake имеет тип возвращаемого значения CGRect, а не CGRect *Таким образом, строка:

CGRect *rect = CGRectMake(0, 0, tableView.frame.size.width,tableView.rowHeight);

должна быть

CGRect rect = CGRectMake(0, 0, tableView.frame.size.width,tableView.rowHeight);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...