إطار viewforheaderince هو دائما نفس الحجم
-
20-09-2019 - |
سؤال
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section != 0) {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
view.backgroundColor = [UIColor redColor];
return view;
} else {
return tableView.tableHeaderView;
}
}
هذا هو تطبيقي للعرض HeadeRinsection ولكن مهما كان الإطار الذي أجعله دائما يظهر لي نفس الإطار الأحمر. هل ترى أي مشكلة في الرمز الخاص بي؟
صورة:
تحديث:
MHM الآن كتلة حمراء أعلى ولكن أول طاولتي هو الآن مخفية بطريقة أو بأخرى. تم تنفيذ أول واحد مع titleforheaderinsection. اعتقدت أنني فقط أقوم بتطبيق ارتفاع الطول الرئيسي ولكن هذا لا يعمل
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
return 30;
else
return tableView.tableHeaderView.frame.size.height;
}
المحلول
تحتاج إلى تنفيذ طريقة المندوب هذه
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section;
في حالتك، يمكنك ببساطة return 30;
.
ايضا، أنت تسريب view
!
لك [view release]
يحدث بعد return
. وبعد ولكن بمجرد return
يحدث طريقة تنفيذ الطريقة تم إحباطها و release
لا يسمى أبدا.
لذلك تريد هذا بدلا من ذلك
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
والتخلص من الصريح release
أسفل أدناه.
لا تنتمي إلى StackOverflow