tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub-views)


問題描述

tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub‑views)

The tableViewHeader property of UITableView is a UIView so I thought I would be able to add multiple sub‑views to it. However, when I added the code for the segmented control the UILabel a few lines before it doesn't draw. Rects shouldn't be overlaping each other. 

What am I doing wrong? 

‑ (void)viewDidLoad {
[super viewDidLoad];

CGRect newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, 50.0);
UIView *trialHeaderView = [[UIView alloc] initWithFrame:newFrame];
trialHeaderView.backgroundColor = [UIColor clearColor];

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(15.0, 10.0, 75.0, 25.0)] autorelease];
label.font = [UIFont boldSystemFontOfSize:12.0];
label.text = @"TaDa!";
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
[trialHeaderView addSubview:label];
[label release];

CGRect frame = CGRectMake(80, 10, 100, 35);
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithFrame:frame];
[seg insertSegmentWithTitle:@"Start" atIndex:0 animated:NO];
[seg insertSegmentWithTitle:@"End" atIndex:1 animated:NO];
[trialHeaderView addSubview:seg];

[seg release];

self.tableView.tableHeaderView = trialHeaderView;
[trialHeaderView release];

}

‑‑‑‑‑

參考解法

方法 1:

Should have updated this earlier...I had autoreleased AND released the same object. silly me...

(by MeltemiMeltemi)

參考文件

  1. tableViewHeader rejecting multiple sub‑views (CC BY‑SA 3.0/4.0)

#cocoa-touch #uiview #uitableview






相關問題

防止 UITableView 在自定義子視圖處理觸摸時滾動 (Prevent UITableView from scrolling when custom subview is handling touches)

NSMutableArray removeObjectAtIndex 在第二次執行時崩潰 (NSMutableArray removeObjectAtIndex crashes on second execution)

Apakah NSURLConnections termasuk dalam model atau pengontrol saya? (Do NSURLConnections belong in my model or controller?)

Lợi ích của việc sử dụng NSString tĩnh cho CellIdentifier là gì? (Whats the advantage of using a static NSString for CellIdentifier?)

CGContextRef 中的坐標係是什麼樣的? (How does the coordinate system in an CGContextRef look like?)

無法在不崩潰的情況下設置 ABPeoplePickerNavigationController 的 addressBook 屬性 (Can't set the addressBook property of ABPeoplePickerNavigationController without crashing)

tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub-views)

界面生成器添加了一個標籤欄按鈕,但未顯示 (Interface builder added one tab bar button, but not showing up)

iVar getter / 方法同名? (iVar getter / method with same name?)

如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)

捕捉返回按鈕導航事件 (Catching back button navigation event)

如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)







留言討論