简单的 UITextView 和 UITableView

发布于 2024-08-05 09:59:30 字数 1090 浏览 2 评论 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;
}

Does anyone have a simple tutorial on how to easily add a TextView to a TableView? Basically re-creating a Settings-style grouped tableview type thing.

Solution:

This is where we setup the object that we want to create, in this example, Im creating a UISwitch; serverSecureAction is where we will put what we want to happen when the switch is triggered.

Code

- (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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作死小能手 2024-08-12 09:59:31

这是我们设置要创建的对象的地方,在本例中,我创建了一个 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;
}

This is where we setup the object that we want to create, in this example, Im creating a UISwitch; serverSecureAction is where we will put what we want to happen when the switch is triggered.

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文