UIView中有标签, 有toolbar,另外还想显示一个表,不是基于导艏的,请问如何在该 UIView视图上显示一个UITableView呢?而且可以对表进行删除行操作 |
|
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];
|
5分 |
楼上是对的,可以设置UITableiew的样式以及可以设置可选和删除
|
5分 |
2楼对的!
|
10分 |
– (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]; NSUInteger row = [indexPath row]; NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); if (sqlite3_open( [path UTF8String], &mydatabase)!=SQLITE_OK) { if (sqlite3_exec(mydatabase,[sqlcmd UTF8String], NULL,NULL, &errmsg)!=SQLITE_OK) { [arr removeObjectAtIndex:row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] NSUInteger row = [indexPath row]; [r.name setText:[a objectAtIndex:0]]; [arr removeObjectAtIndex:row]; } |
IB 里view上加个 tableview ,再绑定 datasource 和delegate。。。代码里实现下就ok了呀
|
|
要实现删除单元行,实现
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } |