2012-04-17 34 views

回答

1

這是你如何添加UISwitch視圖表格單元格。 (作爲附件)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    //add a switch 
    UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero]; 
    cell.accessoryView = switchview; 
    [switchview release]; 
} 

cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; 

return cell; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    //add a switch 
    UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero]; 
    cell.accessoryView = switchview; 
    [switchview release]; 
} 

cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; 

return cell; 
} 
+0

那麼accessoryView中的其他控制器呢?像預覽> 2行 – Burak 2012-04-17 18:24:02

+0

您最好參考Apple的Table View Programming Guide:http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#//apple_ref/doc/uid/TP40007451 – graver 2012-04-17 18:34:57

+0

非常感謝 – Burak 2012-04-17 19:23:14

1

是的,它是一個表視圖控制器..分組的樣式...第一部分有7行 我不能肯定如果派生或不,但我想不...你可以添加視圖到特定的行,所以你可以自定義細胞......派生表細胞不是強制性的

1

不確定你的意思。

如果你的意思是,他們怎麼也UISwitch表格單元格,然後它可能是一個UITableViewCell的,他們把一個UISwitch的子類。

+1

或者他們可能只是添加了'UISwitch'作爲單元的'accessoryView',它不需要子類。但是任何一種方法都行得通,而且我基本上都是分開毛髮。 – Tommy 2012-04-17 18:20:16

+0

對不起,紅色的矩形。我想知道關於交換機的超級視圖。 – Burak 2012-04-17 18:20:21

相關問題