【发布时间】:2013-11-11 10:29:31
【问题描述】:
我添加了一个带有按钮和图像视图的标题视图,但我无法识别图像视图以更改图像。
我的代码如下:
我的 HaderView 类 .h 文件 (HeaderSection.h)
#import <UIKit/UIKit.h>
@interface HeaderViewSection : UIView
@property(nonatomic,retain)UIButton *btn;
@property(nonatomic,retain)UIImageView *arrow_img;
@end
我的 HaderView 类 .m 文件 (HeaderSection.m)
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor brownColor];
_arrow_img=[[UIImageView alloc]init];
_arrow_img.frame=CGRectMake(280, 15, 20, 20);
_arrow_img.image=[UIImage imageNamed:@"Arrow_down_section.png"];
_arrow_img.backgroundColor=[UIColor clearColor];
[self addSubview:_arrow_img];
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(20, 15, 35, 25);
[btn setTitle:@"R" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor blackColor];
[self addSubview:btn];
}
return self;
}
.h 文件
#import "HeaderViewSection.h"
@property (nonatomic,retain)HeaderViewSection *header_view;
.m 文件
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
_header_view = [[HeaderViewSection alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
_header_view.tag = section+5000;
_header_view.btn.tag = section+5000;
[_header_view.btn addTarget:self action:@selector(expandTableHeaderView:) forControlEvents:UIControlEventTouchUpInside];
_header_view.arrow_img.tag=section+2000;
return _header_view;
}
-(void)expandTableHeaderView:(id)sender{
[self.tblView beginUpdates];
NSInteger section = [sender tag];
UIView *view = (UIView *)[_header_view viewWithTag:[sender tag]]; //RETURNS nil
NSArray *arr = [view subviews]; //RETURNS nil
}
我不知道为什么会这样?请帮我解决这个问题。
【问题讨论】:
-
@DivineDesert,你想要什么?
-
好的,我明白你的问题了,@C_X 的回答解决了你的问题吗?
-
@DivineDesert,没有没有解决,只是看看我更新的问题。
-
您在 [sender tag] 中得到的内容
-
-(void)expandTableHeaderView:(id)sender{} 只有在点击按钮时才会调用此方法。那么为什么你可以通过调用 [sender superView] 来获得 headerView;并且可以更改该 headerView 的大小
标签: ios iphone objective-c uitableview tags