samvermette javobiga asoslanib, lekin UITableViewCell kichik sinfidagi tasvirni birlashtirish o‘rniga bevosita fon tasviridan foydalanish uchun o‘zgartirildi. Semning javobi yaxshi, lekin u to'g'ridan-to'g'ri fon tasvirini yaratishdan ko'ra kamroq samarali bo'ladi.
UIView kichik sinfini yarating -- bu misolda men uni CustomTiledView deb nomladim -- va sinfga quyidagi kodni qo'shing:
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"tableview_empty_cell_image"];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM (context, 1, -1);
CGContextDrawTiledImage(context,
CGRectMake(0, 0, rect.size.width, image.size.height),
[image CGImage]);
}
Tableviewcontroller-ga quyidagi kodni qo'shing:
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section {
// this can be any size, but it should be 1) multiple of the
// background image height so the last empty cell drawn
// is not cut off, 2) tall enough that footer cells
// cover the entire tableview height when the tableview
// is empty, 3) tall enough that pulling up on an empty
// tableview does not reveal the background.
return BACKGROUND_IMAGE_HEIGHT * 9; // create 9 empty cells
}
- (UIView *)tableView:(UITableView *)tableView
viewForFooterInSection:(NSInteger)section {
CustomTiledView *footerView = [[CustomTiledView alloc] init];
return [footerView autorelease];
}
Nihoyat, jadval ko'rinishining pastki tarkibini -tableView:heightForFooterInsection:
dan qaytarilgan qiymatning salbiyiga o'rnatishingiz kerak bo'ladi, bu misolda u -1*BACKGROUND_IMAGE_HEIGHT*9
bo'ladi. Pastki tarkibni Interface Builder o'lchami inspektoridan yoki tableviewcontrollerdan self.tableView.contentInset
xususiyatini o'rnatish orqali o'rnatishingiz mumkin.
Salom!
person
memmons
schedule
28.03.2011