У меня есть класс, который расширяется от 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.