0

テーブルビューのヘッダー用のカスタム ビューがあります

UIView *headerTableview_;    
@property (nonatomic, retain) IBOutlet UIView *headerTableview;

私はそれをxibファイルに接続しました。

次に、.m ファイルで、

@synthesize headerTableview = headerTableview_;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  return headerTableview_.frame.size.height;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  return headerTableview_;
}

それから実行してみると、iOS 6 ではうまく表示されますが、iOS 4.3 ではまったく表示されません。

何が問題なのですか?この奇妙な問題を解決する方法を知っている人はいますか? ありがとう!

4

2 に答える 2

0

.h ファイル内

@interface testViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{

UITableView *tableView;
}
@property (retain, nonatomic) IBOutlet UIView *testView;
@end

.m ファイル内

@implementation testViewController

@synthesize testView;
- (void)viewDidLoad
{
[super viewDidLoad];

tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource =self;
[self.view addSubview:tableView];
[self.view bringSubviewToFront:tableView];
// Do any additional setup after loading the view, typically from a nib.
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return testView.frame.size.height;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return testView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Products";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];}
//UIImage *currentTweet = [[xmlParser tweets] objectAtIndex:1];
cell.textLabel.text= @"text label";
cell.detailTextLabel.text=@"detailTextLabel";

return cell;}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)dealloc {
[testView release];
[super dealloc];
}
@end

シミュレータ iOS4.3.2 からの o/p の画像を添付

于 2012-12-05T16:32:28.270 に答える
0

HeaderTableview という名前の新しいクラス ファイルを作成します。IB で割り当てるときに、これが適切に初期化されるかどうかを確認します。

//.h
@class HeaderTableview;

@interface ViewController : UIViewController

@property (nonatomic, retain) IBOutlet HeaderTableview *headerTableview;

//.m
@synthesize headerTableview = _headerTableview;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return _headerTableview.frame.size.height;
}
于 2012-12-05T16:29:51.153 に答える