UIView中有标签, 有toolbar,另外还想显示一个表,不是基于导艏的,请问如何在该 UIView视图上显示一个UITableView呢?而且可以对表进行删除行操作
解决方案 »
- cocos2d-x里面的getContentSize这个函数到底什么意思啊
- 如何将程序上传到appstore上?
- 菜鸟弱弱的问下大神们。
- 有两个viewcontroller,设置每隔几秒钟切换一次 求各位大神解答
- iOS仿微信语音界面部分
- NavigationBar添加的背景图片和ViewController的状态栏不一致,怎么调节?(rt)
- ios里如何手动更改静态表单元的大小和位置
- 为什么[UIImagePickerController isSourceTypeAvailable的值为NO
- 在framework里面调用[NSImage imageNamed:@"a.png”]出错
- iOS系统日历日程缩放效果如何实现
- iphone中如何获取磁盘的剩余空间大小
- 关于窗体切换效果
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];
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];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
}