如何在一个UIView中显示一个UITableView

vysnow 2010-06-11 10:12:13

UIView中有标签, 有toolbar,另外还想显示一个表,不是基于导艏的,请问如何在该 UIView视图上显示一个UITableView呢?而且可以对表进行删除行操作
...全文
809 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
right889138 2010-08-20
  • 打赏
  • 举报
回复
要实现删除单元行,实现
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
right889138 2010-08-20
  • 打赏
  • 举报
回复
IB 里view上加个 tableview ,再绑定 datasource 和delegate。。。代码里实现下就ok了呀
ocwind 2010-08-13
  • 打赏
  • 举报
回复
- (BOOL)tableView:(UITableView *)tableView
canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath {
NSUInteger fromRow = [fromIndexPath row];
NSUInteger toRow = [toIndexPath row];

NSLog(@"%@", arr);

id object = [[arr objectAtIndex:fromRow] retain];

[arr removeObjectAtIndex:fromRow];
[arr insertObject:object atIndex:toRow];
[object release];
}
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {

NSUInteger row = [indexPath row];
NSArray *a = [arr objectAtIndex:row];


NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path=[paths objectAtIndex:0];
path=[path stringByAppendingPathComponent:@"mydata.db"];

if (sqlite3_open( [path UTF8String], &mydatabase)!=SQLITE_OK) {
sqlite3_close(mydatabase);
NSAssert(0,@"failed to open database");
}
char *errmsg;
char *name = [[a objectAtIndex:0] UTF8String];
NSString *sqlcmd=[[NSString alloc]initWithFormat: @"delete from student where name='%s';",name];


if (sqlite3_exec(mydatabase,[sqlcmd UTF8String], NULL,NULL, &errmsg)!=SQLITE_OK) {
sqlite3_close(mydatabase);
NSAssert1(0,@"error update table %s",errmsg);
}

[arr removeObjectAtIndex:row];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSUInteger row = [indexPath row];
NSArray *a = [arr objectAtIndex:row];
Rework *r = [[Rework alloc] init];
[self.navigationController pushViewController:r animated:YES];

[r.name setText:[a objectAtIndex:0]];
[r.age setText:[NSString stringWithFormat:@"%@",[a objectAtIndex:1]]];
[r.number setText:[a objectAtIndex:2]];


[arr removeObjectAtIndex:row];
[r release];

}
ocwind 2010-08-13
  • 打赏
  • 举报
回复
2楼对的!
yuchong1984 2010-08-05
  • 打赏
  • 举报
回复
楼上是对的,可以设置UITableiew的样式以及可以设置可选和删除
shengyx 2010-07-20
  • 打赏
  • 举报
回复
在UIView中添加表格
1、直接在Interface Builder中拖一个来就好了,然后绑定委托,数据
2、代码创建:

self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
UITableView * table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 200) style:UITableViewStylePlain];
//可编辑
table.allowsSelectionDuringEditing = YES;
[self.view addSubview:table];


29,030

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧