2010-05-13 119 views
1

我想爲我的設置屏幕使用UITableView。因此,我的設置視圖看起來像蘋果,組表視圖,然後用戶界面元素,讓您更改設置。iPhone:UITableView與自定義單元格設置

所以,它似乎不像單元格從數組中加載,但似乎每個單元都是自定義的。

想法如何做到這一點?

回答

2

對於初學者,請將tableViewStyle屬性設置爲UITableViewStyleGrouped。 然後更改數據源以提供具有所需組的二維數組,而不是簡單的數組。實際上這很簡單。

您將需要使用UIControl類型自定義該行 - 我假設您已經這樣做了。

編輯:

要控制添加到該行,當您創建單元創建它。

... 
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button setFrame:CGRectMake(0.0f, 5.0f, 30.0f, 30.0f)]; 

[button setTitle:@"Click Me!" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
[cell addSubview:button]; 
... 
+0

是的,我已經將它設置爲分組。我想我對如何使用一個數組這個問題感到困惑,因爲每個單元格都會有不同的佈局。 – 2010-05-13 22:40:19

+0

編輯與我認爲你在找什麼 – psychotik 2010-05-13 22:59:52

0

你可以不用數組。只需使用以下方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

然後可以使用switch-method來解析所有行和段。這兩個方法在頂部的方法頭上,你可以將它縮短一點。

NSUInteger row = [indexPath row]; 
NSUInteger section = [indexPath section]; 

不要忘記,手動tableviews容易出錯。

歡呼西蒙