关于在view当中增加toolbar的问题


在view当中,增加toolbar,往往会导致toolbar跟着tableview一起滚动。

为了改善这种状况,通常的做法是,将toolbar和tableview都加入到父类的view当中去。


其实比较简单的参考例子如下:


NSString * strfilepath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"bookname.plist"];

list = [[NSMutableArray alloc] initWithContentsOfFile:strfilepath];

CGRect rectframe = CGRectMake(0, 0, 320, 460);

mytable =[[UITableView allocinitWithFrame:rectframe style:UITableViewStylePlain];

mytable.delegate = self;

mytable.dataSource =self;

[self.view addSubview:mytable];

CGRect tframe;

CGRect bound;

bound = [[UIScreen mainScreen] applicationFrame];

tframe = CGRectMake(0, bound.size.height - 50, bound.size.width, 50);

toolbar  = [[UIToolbar alloc] initWithFrame:tframe];

toolbar.backgroundColor = [UIColor blueColor];

toolbar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;

medit = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:nil];

toolbar.items = [NSArray arrayWithObjects:medit,nil];

[self.view addSubview:toolbar];


//对于tableview的具体的读取内容的做法如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell * cell = nil;

CGRect rectFrame = CGRectMake(0, 0, 320, 30) ;

cell = [[[UITableViewCell alloc] initWithFrame:rectFrame reuseIdentifier:@""] autorelease];

NSString *strCon = [list objectAtIndex:indexPath.row];

UILabel *text = [[UILabel alloc] initWithFrame: cell.frame];

[text setFont:[UIFont boldSystemFontOfSize:20]];

[text setText:strCon];

[cell addSubview:text];

[strCon release];

return cell;


}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值