有2个tableview ,atableview 把一个数组传到Btableview里面,然后在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
方法中对比atableview的 button.tag 如果之前的相同的button.tag就回隐藏某一个btn.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"B2Cell%d%d", [indexPath section], [indexPath row]];
//以indexPath来唯一确定cell
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
if (Cell == nil) {
Cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSInteger Row = [indexPath row];
Cell.textLabel.text = [B2Array objectAtIndex:Row];
Cell.textLabel.numberOfLines =0;
//建立5个button
UIButton *btn5 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn5 setTag:100+Row*5];
btn5.frame = CGRectMake(120.0f, 0.0f, 30.0f, 40.0f);
[btn5 setTitle:@"" forState:UIControlStateNormal];
UIImage * buttonImageNormal=[UIImage imageNamed:@"5.jpg"];
[btn5 setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
[btn5 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn4 setTag:100+Row*5+1];
btn4.frame = CGRectMake(160.0f, 0.0f, 30.0f, 40.0f);
[btn4 setTitle:@"4" forState:UIControlStateNormal];
[btn4 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn3 setTag:100+Row*5+2];
btn3.frame = CGRectMake(200.0f, 0.0f, 30.0f, 40.0f);
[btn3 setTitle:@"3" forState:UIControlStateNormal];
[btn3 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn2 setTag:100+Row*5+3];
btn2.frame = CGRectMake(240.0f, 0.0f, 30.0f, 40.0f);
[btn2 setTitle:@"2" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTag:100+Row*5+4];
btn1.frame = CGRectMake(270.0f, 0.0f, 30.0f, 40.0f);
[btn1 setTitle:@"1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
//B1GetArray从aview传过来的数组。和每一个button tag 对比。进行隐藏按钮
for (int i;i<[B1GetArray count];i++) {
int tagB1 = [[B1GetArray objectAtIndex:i] intValue];
NSLog(@"%i",btn1.tag);
if (btn1.tag==tagB1){
btn1.hidden=YES;
}
else{
btn1.hidden=NO;
}
btn1输出的永远是一个数值,是我的逻辑有问题么?如果我把btn1 放在for循环下面 我所有的tag都回读出来。但是在for里面就只会读一个。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
方法中对比atableview的 button.tag 如果之前的相同的button.tag就回隐藏某一个btn.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"B2Cell%d%d", [indexPath section], [indexPath row]];
//以indexPath来唯一确定cell
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
if (Cell == nil) {
Cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSInteger Row = [indexPath row];
Cell.textLabel.text = [B2Array objectAtIndex:Row];
Cell.textLabel.numberOfLines =0;
//建立5个button
UIButton *btn5 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn5 setTag:100+Row*5];
btn5.frame = CGRectMake(120.0f, 0.0f, 30.0f, 40.0f);
[btn5 setTitle:@"" forState:UIControlStateNormal];
UIImage * buttonImageNormal=[UIImage imageNamed:@"5.jpg"];
[btn5 setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
[btn5 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn4 setTag:100+Row*5+1];
btn4.frame = CGRectMake(160.0f, 0.0f, 30.0f, 40.0f);
[btn4 setTitle:@"4" forState:UIControlStateNormal];
[btn4 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn3 setTag:100+Row*5+2];
btn3.frame = CGRectMake(200.0f, 0.0f, 30.0f, 40.0f);
[btn3 setTitle:@"3" forState:UIControlStateNormal];
[btn3 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn2 setTag:100+Row*5+3];
btn2.frame = CGRectMake(240.0f, 0.0f, 30.0f, 40.0f);
[btn2 setTitle:@"2" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTag:100+Row*5+4];
btn1.frame = CGRectMake(270.0f, 0.0f, 30.0f, 40.0f);
[btn1 setTitle:@"1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(asender:) forControlEvents:UIControlEventTouchUpInside];
//B1GetArray从aview传过来的数组。和每一个button tag 对比。进行隐藏按钮
for (int i;i<[B1GetArray count];i++) {
int tagB1 = [[B1GetArray objectAtIndex:i] intValue];
NSLog(@"%i",btn1.tag);
if (btn1.tag==tagB1){
btn1.hidden=YES;
}
else{
btn1.hidden=NO;
}
btn1输出的永远是一个数值,是我的逻辑有问题么?如果我把btn1 放在for循环下面 我所有的tag都回读出来。但是在for里面就只会读一个。
解决方案 »
- Mac下网络架构设计软件
- 为什么build scuess但是运行的时候出现breakpoint的提示?
- iOS解析XML文档问题
- vmware虚拟机中装了雪豹10.6 MAC系统, XCode4安装不了, 各位有什么解决办法吗?
- 菜鸟关于uitableviewcell的问题
- 怎样让uiwebview里 点击的网页链接 支持uinavigationbar的返回操作?
- IOS 唯一标识符
- 如何实现在一个viewcontroller上加载另一个viewcontroller
- iOS上手动写出一个字,识别写的是那个字,怎么实现?
- oc的framework怎么统计覆盖率
- 如何自定义tableViewCell的向左滑动出现的按钮
- openssl 解析X509 主题 subject 中文乱码
1 所有的button都没有加入super view
2 for循环中的nslog()位于if判断之外,在for循环执行过程中,肯定输出相同的值;