0

有没有人有关于如何轻松地将 TextView 添加到 TableView 的简单教程?基本上是重新创建一个设置风格的分组表视图类型的东西。

解决方案:

这是我们设置我们想要创建的对象的地方,在这个例子中,我正在创建一个UISwitch; serverSecureAction是我们将在触发开关时放置我们想要发生的事情的地方。

代码

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

    serverSecure = [[[UISwitch alloc] initWithFrame:CGRectMake(197, 8, 94, 27)] autorelease];
    serverSecure.tag = kServerTag;
    [serverSecure addTarget:self action:@selector(serverSecureAction:) forControlEvents:UIControlEventValueChanged];
    serverSecure.backgroundColor = [UIColor clearColor];

    switch (indexPath.row)
    {
        case 0:
        {
            /*  This is where we add the subview we created above, 
                this can be used for any type of object.
             */
            [cell.textLabel setText: NSLocalizedString(@"Connect Secure", @"")];
            [cell setAccessoryView: serverSecure];
            [serverSecure setOn: TRUE];
        }
            break;
    }
    //.... 
    retun Cell;
}
4

1 回答 1

0

这是我们设置我们想要创建的对象的地方,在这个例子中,我正在创建一个UISwitch; serverSecureAction是我们将在触发开关时放置我们想要发生的事情的地方。

serverSecure = [[[UISwitch alloc] initWithFrame:CGRectMake(197, 8, 94, 27)] autorelease];
serverSecure.tag = kServerTag;
[serverSecure addTarget:self action:@selector(serverSecureAction:) forControlEvents:UIControlEventValueChanged];
serverSecure.backgroundColor = [UIColor clearColor];

switch (indexPath.row)
{
    case 0:
    {
        /*  This is where we add the subview we created above, 
            this can be used for any type of object.
         */
        [cell.textLabel setText: NSLocalizedString(@"Connect Secure", @"")];
        [cell setAccessoryView: serverSecure];
        [serverSecure setOn: TRUE];
    }
        break;
}
于 2009-09-22T17:59:15.610 回答