简单的 UITextView 和 UITableView
有人有关于如何轻松地将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我们设置要创建的对象的地方,在本例中,我创建了一个 UISwitch;
serverSecureAction
是我们在触发切换时放置我们想要发生的事情的地方。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.