UITableView中的按钮
问题描述:
我想创建UITableView,其中一些单元格是按钮。 帮助我,正确的做法是什么?UITableView中的按钮
1)我可以使用类似的东西:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
if (indexPath.section == 1){
if (indexPath.row == 0){
UIButton* loginButton = [[UIButton alloc] initWithFrame:CGRectMake(9,1,302, 48)];
[loginButton setBackgroundImage:[UIImage imageNamed:@"LoginButton.png"] forState:UIControlStateNormal];
[loginButton setBackgroundImage:[UIImage imageNamed:@"LoginButton_pressed.png"] forState:UIControlStateSelected];
[loginButton setTitle:@"Login" forState:UIControlStateNormal];
[cell setBackgroundColor:[UIColor clearColor]];
[cell addSubview:loginButton];
[loginButton release];
}
}
但我看到那个按钮是透明的,看起来很奇怪。
2)不使用任何UIButtons,让我想要完全使用UITableViewCells
谢谢你们四个的关注,我很为iOS完全新的,但我试图让应用无需厦门国际银行。
。所以您不能直接分配给它这样改变这样的代码
答
您还没有设置按钮式,它是只读属性:
UIButton* loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[loginButton setFrame:CGRectMake(5,5,302, 34)];
[loginButton setBackgroundImage:[UIImage imageNamed:@"LoginButton.png"] forState:UIControlStateNormal];
[loginButton setBackgroundImage:[UIImage imageNamed:@"LoginButton_pressed.png"] forState:UIControlStateSelected];
[loginButton setTitle:@"Login" forState:UIControlStateNormal];
[cell setBackgroundColor:[UIColor clearColor]];
[cell addSubview:loginButton];
默认按钮式将自定义所以设置类型buttonWithType :UIButtonTypeRoundedRect – 2013-02-20 07:03:24