У меня есть класс, который простирается от UIView. Я использовал это для создания пользовательского представления по умолчанию. Я использую -(id)initWithFrame:(CGRect)frame;
, но когда я использовал инициализатор, параметр frame
всегда равен null
.переопределяет UIView: initWithFrame и получил нулевые параметры
Вот код:
#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, но я использовал некоторые взгляды на некоторые UILabel тоже.
Пожалуйста, покажите нам код, где вы называете 'initWithFrame:'. –
done, я добавил источник, где я вызываю 'initWithFrame' – Suprie